#Using the class-transformer

2 messages · Page 1 of 1 (latest)

old talon
#

I'm trying to use the class-transformer's plainToClass function to return a mapped object, I can get all the parameters using "excludeExtraneousValues: true" but I need to exclude some parameters and use only the @Expose decorator doesn't work for address ```ts
@Get(':id')
async getOne(@Param('id') id: number): Promise<UserResponseDto> {
const user = await this.getUserByIdUseCase.execute(id);
console.log(user.address);
return plainToClass(UserResponseDto, user, {
excludeExtraneousValues: true,
});
}

#
export class UserResponseDto {
  @Expose()
  id: number;

  @Expose()
  name: string;

  @Expose()
  cpf: string;

  @Expose()
  email: string;

  @Expose()
  phone: string;

  @Expose()
  typeUser: number;

  @Expose()
  address?: AddressResponseDTO[];
}
``` ```ts
export class AddressResponseDTO {
  @Expose()
  id: number;

  @Expose()
  userId: number;

  @Expose()
  cityId: number;

  @Expose()
  cep: string;

  @Expose()
  addressNumber: number;

  @Expose()
  complement: string;
}