Created
December 19, 2024 11:16
-
-
Save nejdetkadir/eb9996cd22c6bacc37a381e8da7b365a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { plainToClass } from 'class-transformer'; | |
import { PromptEntity } from '@app/modules/prisma/prompt.entity'; | |
import { AdminEntity } from '@app/modules/prisma/admin.entity'; | |
import { ProfileEntity } from '@app/modules/prisma/profile.entity'; | |
import { UserEntity } from '@app/modules/prisma/user.entity'; | |
type Constructor<T = {}> = new (...args: any[]) => T; | |
function WithClassMapping<T extends Constructor>(Base: T) { | |
return class extends Base { | |
mapPromptEntity(value: any): PromptEntity { | |
return plainToClass(PromptEntity, value); | |
} | |
mapPromptEntities(values: any[]): PromptEntity[] { | |
return values.map((value) => this.mapPromptEntity(value)); | |
} | |
mapAdminEntity(value: any): AdminEntity { | |
return plainToClass(AdminEntity, value); | |
} | |
mapAdminEntities(values: any[]): AdminEntity[] { | |
return values.map((value) => this.mapAdminEntity(value)); | |
} | |
mapProfileEntity(value: any): ProfileEntity { | |
return plainToClass(ProfileEntity, value); | |
} | |
mapProfileEntities(values: any[]): ProfileEntity[] { | |
return values.map((value) => this.mapProfileEntity(value)); | |
} | |
mapUserEntity(value: any): UserEntity { | |
return plainToClass(UserEntity, value); | |
} | |
mapUserEntities(values: any[]): UserEntity[] { | |
return values.map((value) => this.mapUserEntity(value)); | |
} | |
}; | |
} | |
class BaseService { | |
constructor() {} | |
} | |
export const ApplicationService = WithClassMapping(BaseService); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment