How to transform database entity User
:
class User {
public firstName: string;
public lastName: string;
public phone?: string;
public email: string;
public status: EUserState;
public tokens: Token[];
public password: string;
}
into DTO entity GetUserDTO
:
class GetUserDTO {
public id: number;
public firstName: string;
public lastName: string;
public phone?: string;
public email: string;
}
in TypeScript? I am using @nestjs
, class-validator
and class-transformer
packages, but I not found any way to use them to achieve this.
Somebody can say, that having DTO is pointless for this, but we have DTOs shared between server and client to maintain API structure.
Any ideas?
Dto.fromDomain
should be preferred. – Tallith