Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
NestJs: DTO showing all query parameters

I'm trying to use 2 separate dto for query parameters in NestJs. However, on printing both dtos are showing same properties. Is there any way to separate them.

// dto code

export class PageDto {
  @Type(() => Number)
  @IsInt()
  page: number;

  @Type(() => Number)
  @IsInt()
  limit: number;
}

export class MyDto {
  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  status: string;

  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  source: string;
}

Api request:

GET url?page=1&limit=10&status='active'&source='firebase'

controller:

@Get()
  async get(
    @Query() myDto: MyDto,
    @Query() pageDto: PageDto,
  ) {
     console.log({pageDto}, {myDto});
  } 

Console statement prints:

{
   pageDto: {
    page: 1,
    limit: 10,
    status: 'active',
    source: 'firebase'
   }
}

{
   myDto: {
    page: 1,
    limit: 10,
    status: 'active',
    source: 'firebase'
   }
}

Required:

{
   pageDto: {
    page: 1,
    limit: 10
   }
}

{
   myDto: {
    status: 'active',
    source: 'firebase'
   }
}

Ideally, pageDto and myDto should show their respective properties.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You'll need to set whitelist: true in your ValidationPipe options to tell class-transformer and class-validator to strip out the properties that don't exist on the DTO.

Reference to the docs

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!