I want to use a white list in my route's body validation. I expect that only data is accepted that confirms to my model and if some parameter is sent that is not part of my model DTO an error must be thrown.
This is my DTO :
export class RegisterDTO {
@MinLength(5)
userName: string;
@MinLength(8)
password: string;
@IsNotEmpty()
seller: boolean;
address: {
city: string;
street: string;
apartment?: string;
};
}
This is my controller :
@Post('register')
@UsePipes(new ValidationPipe({ transform: true, whitelist: true}))
async register(@Body() userDTO: RegisterDTO) {
const user = await this.userService.create(userDTO);
const payload: Payload = {
userName: user.userName,
seller: user.seller,
};
const token = await this.authService.signPayload(payload);
return {user, token};
}
But when I sent this data I dont get an error:
{
"userName": "userdasdnasdasdadad",
"password": "passwdasdasdasadasdasda",
"address": {
"city": "kiev",
"street": "amosova"
},
"seller": false,
"test": "test"
}
"test": "test" must be not allowed as a parameter; I expect an error to be thrown but there is none