我有一个DTO
render() {
var webgraph = require("@ustutt/grapheditor-webcomponent");
GraphEditor.
return (
<network-graph classes="red blue" mode="layout" zoom="both">
<style slot="style">
svg {width:100%; height: 100%}
</style>
<svg slot="graph"></svg>
</network-graph>
)
}}
我的控制器看起来像这样
export class UpdateUserRoleDTO {
@ApiProperty()
@IsNotEmpty()
readonly userId:number;
@ApiProperty()
@IsNotEmpty()
@IsNumber()
readonly roleId: number;
}
每当客户端发送具有以下有效负载的请求
@UsePipes(new ValidationPipe())
@Post('/update')
async updateUser(@Body() updateUserDto: UpdateUserDTO): Promise<User> {
return await this.userService.updateUser(updateUserDto);
}
它正在打我的服务文件。我要避免这种情况,请确保仅传递DTO中提到的参数,否则应给出400
答案 0 :(得分:0)
鉴于您的代码,我会将设置为 true 的whitelist选项传递给您要实例化的ValidationPipe
,就像在您的实例中一样控制器:
@UsePipes(new ValidationPipe({ whitelist: true }))
@Post('/update')
async updateUser(@Body() updateUserDto: UpdateUserDTO): Promise<User> {
return await this.userService.updateUser(updateUserDto);
}
这应该可以完成工作。
让我知道是否有帮助,否则请随时评论和分享您的发现;)