我正在使用 NestJs 创建一个 API,我目前有一个端点帖子,它接收参数、处理它并响应。我遇到的问题是我想更改参数的名称,但仅在 Json 级别,我尝试使用 Expose 装饰器,但它会更改整个项目的属性。
令牌.控制器.ts
@Post()
async create(@Body() createTokenDto: CreateTokenDto) {
return await this.tokensService.create(createTokenDto);
}
创建令牌.dto.ts
export class CreateTokenDto {
@IsString()
@IsNotEmpty()
@Length(36)
@Expose({ name: 'product_uuid' })
productUuid: string;
}
问题在于,现在 CreateTokenDto 对象的值 productUuid 始终为 null,有没有办法将属性仅更改为它接收到的 json?