-
Notifications
You must be signed in to change notification settings - Fork 845
Open
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.
Description
I was trying to use whitelist alongside the inheriting
I have a dto, this dto would be used whenever the common user trys to create a user:
class CreateUserDto {
@IsString()
name: string;
}And admin can create user too, but admin can specify more fields:
class AdminCreateUserDto extends CreateUserDto {
@IsNumber()
credit: number;
}now In the controller I have:
// first scenario: disabled whaitelist
async adminCreateUser(@Body({ validate: { whitelist: false } }) user: AdminCreateUserDto) {
/*
* POST /users
* body: { name: "nodejs", credit: 1000 }
*/
console.log(user); // { name: "nodejs", credit: 1000 }
}
// second scenario: acvtived whitelist
async adminCreateUser(@Body({ validate: { whitelist: true } }) user: AdminCreateUserDto) {
/*
* POST /users
* body: { name: "as", credit: 1000 }
*/
console.log(user); // { credit: 1000 }
}The problem:
As you can see I do not have the name field. My expectation is to get the same result in the second scenario.
- Node: v14.17.6
- npm: 6.14.15
- class-validator: ^0.13.1
leite08 and MostajeranMohammad
Metadata
Metadata
Assignees
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.