Commit 1f569dca authored by nanahira's avatar nanahira

fix class name conflict

parent ad54ab9d
...@@ -31,6 +31,7 @@ import { CreatePipe, GetPipe, UpdatePipe } from './pipes'; ...@@ -31,6 +31,7 @@ import { CreatePipe, GetPipe, UpdatePipe } from './pipes';
import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
import _ from 'lodash'; import _ from 'lodash';
import { getSpecificFields } from '../utility/metadata'; import { getSpecificFields } from '../utility/metadata';
import { RenameClass } from '../utility/rename-class';
export interface RestfulFactoryOptions<T> { export interface RestfulFactoryOptions<T> {
fieldsToOmit?: (keyof T)[]; fieldsToOmit?: (keyof T)[];
...@@ -52,17 +53,26 @@ export class RestfulFactory<T> { ...@@ -52,17 +53,26 @@ export class RestfulFactory<T> {
this.entityClass, this.entityClass,
this.fieldsToOmit, this.fieldsToOmit,
) as ClassType<T>; ) as ClassType<T>;
readonly createDto = OmitType( readonly createDto = RenameClass(
this.basicDto, OmitType(
getSpecificFields(this.entityClass, 'notWritable') as (keyof T)[], this.basicDto,
getSpecificFields(this.entityClass, 'notWritable') as (keyof T)[],
),
`Create${this.entityClass.name}Dto`,
) as ClassType<T>; ) as ClassType<T>;
readonly importDto = ImportDataDto(this.entityClass); readonly importDto = ImportDataDto(this.entityClass);
readonly findAllDto = PartialType(this.basicDto) as ClassType<T>; readonly findAllDto = RenameClass(
readonly updateDto = PartialType( PartialType(this.basicDto),
OmitType( `Find${this.entityClass.name}Dto`,
this.createDto, ) as ClassType<T>;
getSpecificFields(this.entityClass, 'notChangeable') as (keyof T)[], readonly updateDto = RenameClass(
PartialType(
OmitType(
this.createDto,
getSpecificFields(this.entityClass, 'notChangeable') as (keyof T)[],
),
), ),
`Update${this.entityClass.name}Dto`,
) as ClassType<T>; ) as ClassType<T>;
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
readonly idType: Function = Reflect.getMetadata( readonly idType: Function = Reflect.getMetadata(
......
export function RenameClass<T>(cls: T, name: string) {
Object.defineProperty(cls, 'name', { value: name });
return cls;
}
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