我面临一个招摇的问题,我不知道如何继续。
假设我们有 catDto
export class catDto {
@ApiProperty({
type: String,
readonly: true
})
uuid: string;
@ApiProperty({
enum: GenderEnum
})
gender: GenderEnum;
@ApiProperty({
type: String
})
name: string;
}
我们的控制器是
@Controller()
export class catController {
@Post()
@UseGuards(AuthGuard("JWT"))
public async createCat(@Body() cat: catDto){
////// creates cat based on catDto
}
@Get(":uuid")
@UseGuards(AuthGuard("JWT"))
public async getCat(@Param('uuid') uuid: string){
/////// returns cat based on uuid
}
@Put(":uuid")
@UseGuards(AuthGuard("JWT"))
public async updateCat(@Param('uuid') uuid: string, @Body() cat: catDto){
////// updates cat based on catDto
}
}
问题出在@Put 中。
我想要一个简单的用户只更新 catDto 的属性“名称”,而管理员也可以更改其性别。
这怎么可能?
(我已经在使用 JWT 不记名身份验证)
版本:@nestjs/swagger:^4.7.8 节点:14.17.0