1

I am using NestJs to create an API, I currently have an endpoint post that receives parameters, processes it, and responds. The problem I have is that I want to change the name of a parameter, but only at the Json level, I tried with the Expose decorator, but it changes the attribute throughout the project.

tokens.controllers.ts

@Post()
async create(@Body() createTokenDto: CreateTokenDto) {
  return await this.tokensService.create(createTokenDto);
}

create-token.dto.ts

export class CreateTokenDto {
  @IsString()
  @IsNotEmpty()
  @Length(36)
  @Expose({ name: 'product_uuid' })
  productUuid: string;
}

The problem with this, is that now the CreateTokenDto object has the value productUuid is always null, is there any way to change the attribute only to the json it receives?

normeno
  • 105
  • 1
  • 10
  • Can you please explain what you mean by `change the attribute only to the json`? – CyberEternal Jul 09 '21 at 20:11
  • 1
    When I use the `@Expose ({name: "product"})` decorator, whoever invokes my service can do it with the json `{"product_uuid": "value"}`, but that means internally in code, I can no longer use `createTokenDto.productUuid`, since this has no value. What I need is that in the json they send me, they send me product_uuid, but I work it as productUuid – normeno Jul 09 '21 at 21:31

0 Answers0