Commit 801ad559 authored by nanahira's avatar nanahira

more free types

parent 5fea4da9
......@@ -29,11 +29,11 @@ import {
import { CreatePipe, GetPipe, UpdatePipe } from './pipes';
import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
export interface CrudFactoryOptions<T extends TimeBase> {
export interface RestfulFactoryOptions<T> {
fieldsToOmit?: (keyof T)[];
}
export class RestfulFactory<T extends TimeBase> {
export class RestfulFactory<T> {
readonly createDto: ClassType<Omit<T, keyof T>>;
readonly updateDto: ClassType<Partial<Omit<T, keyof T>>>;
readonly entityReturnMessageDto = ReturnMessageDto(this.entityClass);
......@@ -45,10 +45,10 @@ export class RestfulFactory<T extends TimeBase> {
constructor(
public readonly entityClass: ClassType<T>,
private options: CrudFactoryOptions<T> = {},
private options: RestfulFactoryOptions<T> = {},
) {
this.createDto = OmitType(this.entityClass, [
...TimeBaseFields,
...(TimeBaseFields as (keyof T)[]),
...(options.fieldsToOmit || []),
]);
this.updateDto = PartialType(this.createDto);
......
import { SelectQueryBuilder } from 'typeorm';
import { TimeBase } from '../bases/time-base';
export function applyQueryProperty<T extends TimeBase>(
export function applyQueryProperty<T>(
obj: T,
qb: SelectQueryBuilder<T>,
entityName: string,
......@@ -14,7 +13,7 @@ export function applyQueryProperty<T extends TimeBase>(
qb.andWhere(`${entityName}.${field} = :${field}`, { [field]: obj[field] });
}
}
export function applyQueryPropertyLike<T extends TimeBase>(
export function applyQueryPropertyLike<T>(
obj: T,
qb: SelectQueryBuilder<T>,
entityName: string,
......@@ -30,7 +29,7 @@ export function applyQueryPropertyLike<T extends TimeBase>(
}
}
export function applyQueryPropertySearch<T extends TimeBase>(
export function applyQueryPropertySearch<T>(
obj: T,
qb: SelectQueryBuilder<T>,
entityName: string,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment