Bird
0
0

You want to accept a query parameter count that must be an integer greater than zero. Which combination correctly uses ParseIntPipe with validation in NestJS?

hard📝 Application Q8 of 15
NestJS - Pipes
You want to accept a query parameter count that must be an integer greater than zero. Which combination correctly uses ParseIntPipe with validation in NestJS?
A@Query('count', ParseIntPipe) count: number; if (count <= 0) throw new Error()
B@Query('count', new ParseIntPipe({ min: 1 })) count: number
C@Query('count', ParseBoolPipe) count: boolean
D@Query('count') count: string
Step-by-Step Solution
Solution:
  1. Step 1: Use ParseIntPipe with options for validation

    ParseIntPipe accepts options like min to enforce minimum value during parsing.
  2. Step 2: Identify correct syntax for min validation

    Using new ParseIntPipe({ min: 1 }) ensures count is parsed and validated to be at least 1.
  3. Final Answer:

    @Query('count', new ParseIntPipe({ min: 1 })) count: number -> Option B
  4. Quick Check:

    ParseIntPipe supports min option for validation [OK]
Quick Trick: Use ParseIntPipe with options for min/max validation [OK]
Common Mistakes:
  • Manually validating after pipe
  • Using ParseBoolPipe for numbers
  • Not validating count at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes