0
0
NestJSframework~20 mins

Built-in pipes (ParseIntPipe, ParseBoolPipe) in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NestJS Pipes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when ParseIntPipe receives a non-numeric string?
Consider a NestJS controller method using @Param('id', ParseIntPipe). What will happen if the URL parameter id is 'abc'?
NestJS
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';

@Controller('items')
export class ItemsController {
  @Get(':id')
  getItem(@Param('id', ParseIntPipe) id: number) {
    return { id };
  }
}
AThe method will receive the string 'abc' as the id parameter without error.
BThe method will receive NaN as the id parameter.
CThe request will fail with a 400 Bad Request error because 'abc' cannot be converted to a number.
DThe method will receive the number 0 as the id parameter.
Attempts:
2 left
💡 Hint
ParseIntPipe tries to convert the input to a number and throws if it fails.
state_output
intermediate
2:00remaining
What value does ParseBoolPipe produce for 'false' string?
Using @Query('active', ParseBoolPipe) in a NestJS controller, what will be the value of active if the query parameter is ?active=false?
NestJS
import { Controller, Get, Query, ParseBoolPipe } from '@nestjs/common';

@Controller('users')
export class UsersController {
  @Get()
  getUsers(@Query('active', ParseBoolPipe) active: boolean) {
    return { active };
  }
}
AThe value of active will be true because any string is truthy.
BThe value of active will be the string 'false'.
CThe request will fail with a 400 Bad Request error.
DThe value of active will be the boolean false.
Attempts:
2 left
💡 Hint
ParseBoolPipe converts 'true' and 'false' strings to booleans.
📝 Syntax
advanced
2:00remaining
Which option correctly applies ParseIntPipe to a route parameter?
Select the correct NestJS controller method signature that uses ParseIntPipe to convert the userId route parameter to a number.
A
@Get(':userId')
getUser(@Param('userId', ParseIntPipe) userId: number) { return userId; }
B
@Get(':userId')
getUser(@Param(ParseIntPipe) userId: number) { return userId; }
C
@Get(':userId')
getUser(@Param('userId') userId: ParseIntPipe) { return userId; }
D
@Get(':userId')
getUser(@Param('userId') userId: number, ParseIntPipe) { return userId; }
Attempts:
2 left
💡 Hint
The pipe is passed as the second argument to @Param decorator.
🔧 Debug
advanced
2:00remaining
Why does ParseBoolPipe throw an error for query '?flag=yes'?
Given this controller method:
getFlag(@Query('flag', ParseBoolPipe) flag: boolean) { return flag; }
What causes the error when the query string is ?flag=yes?
AParseBoolPipe converts 'yes' to true, so no error occurs.
BParseBoolPipe only accepts 'true' or 'false' strings; 'yes' is invalid and causes a 400 error.
CThe query parameter 'flag' is missing, causing a null error.
DThe controller method is missing a return statement, causing an error.
Attempts:
2 left
💡 Hint
ParseBoolPipe expects specific string values.
🧠 Conceptual
expert
3:00remaining
How do ParseIntPipe and ParseBoolPipe improve API robustness?
Choose the best explanation of how using ParseIntPipe and ParseBoolPipe in NestJS controllers helps API reliability.
AThey automatically validate and convert input parameters, preventing invalid data from reaching business logic and returning clear errors to clients.
BThey cache parsed values to improve performance of repeated requests.
CThey encrypt input parameters to secure sensitive data during transmission.
DThey log all incoming parameters for auditing purposes.
Attempts:
2 left
💡 Hint
Think about input validation and error handling.