Advertisement
nodejsdeveloperskh

class-validator, whitelist, extends logical bug

Sep 11th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // class validators
  2. class CreateUserDto {
  3.   @IsStromg
  4.   name: string;
  5. }
  6.  
  7. class AdminCreateUserDto extends CreateUserDto {
  8.   @IsStromg
  9.   disabled: boolean;
  10. }
  11.  
  12.  
  13. // disabled whaitelist
  14. async adminCreateUser(
  15.   @Body({ validate: { whitelist: false } }) user: AdminCreateUserDto
  16. ) {
  17.   /*
  18.    * POST /users
  19.    * body: { name: "as", disabled: true }
  20.    */
  21.   console.log(user); // { name: "as", disabled: true }
  22. }
  23.  
  24. // avtived whitelist
  25. async adminCreateUser(
  26.   @Body({ validate: { whitelist: true } }) user: AdminCreateUserDto
  27. ) {
  28.   /*
  29.    * POST /users
  30.    * body: { name: "as", disabled: true }
  31.    */
  32.   console.log(user); // { disabled: true }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement