When using ValidationPipe to turn on the transformer option, the Query annotation will produce wrong behavior
app.useGlobalPipes(
new ValidationPipe({
transform: false,
whitelist: true,
forbidNonWhitelisted: true,
}),
);
// controller
@Get("role")
getUserRole(@Query("uid") uid: number) {
return this.userService.userIsExitsts(uid).then((exists) => {
if (!exists) {
throw new NotFoundException(`can not found this user ${uid}`);
}
return this.userService.getUserInforByUID(uid).then((userinfor) => {
return userinfor.role;
});
});
}
if transformis true, then uid will be NaN.