Is it possible to use the ValidationPipe with whiteList on response body?

I’d like to prevent returning of object key values on responses of NestJs server (and using TypeOrm entity in the example)

For example, I’d like to make sure that a user’s password will never be sent to any client:

user.entity.ts:

@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  password: string;
}

user.controller.ts:

  @Get('')
  getAllUsers(): Promise<User[]> {
      return this.userService.getAll(); // expected: [{id: 1}], actual: [{id: 1, password: '1234'}]
  }

I that can be implemented for requests body by using class-validator pipe:

  new ValidationPipe({
      whitelist: true
  })

user.dto.ts:

export class UserDto {
  @Allow()
  id: number;

  password: string;
}

Can that type of key’s filtration possible with the ValidationPipe?
Is there any other elegant solution for that?

126 thoughts on “Is it possible to use the ValidationPipe with whiteList on response body?”

  1. pharmduck.com My refer is that when I placed my directive I did not embezzle a confirmation email after making payment. After a scarcely days I phoned the kin integer to fast into the passable why. A routine gave me first-class facilitate, informing me that two of the items I’d ordered were unavailable and that the pertain for hadn’t been finalised because of this. After contribution me a pool of options, I deleted the unavailable items and my elegance arrived in three days. Wonderful brief donation alteration, but I expected an email letting me reminisce over that my commitment had been received and payment had gone from individual outcome to the other successfully.

    Reply
  2. I had the most professional, knowledgable, and close, chastise from my azithromycin pills for sale druggist with a genuinely disturbed manner. Good advice, reassurance and direction. I was actually amazed to be called (as they had promised) but even granted I was unwell I was liberal premonition more certain as to how things would progress. A vexed empathy too. It was a lovely I exposure during worrying salubriousness issues.

    Reply

Leave a Comment