Pipes, Guards & Interceptors — Series 2

Preview — 3 of 10 questions

What does this pipe accept, and what happens for ?active=yes?

javascript
@Get()
findAll(@Query('active', ParseBoolPipe) active: boolean) {
  return this.catsService.findAll(active);
}
AIt accepts any non-empty string as true, so yes becomes true
BIt accepts the strings 'true' and 'false' (and real booleans), converting them to the matching boolean; yes is rejected with a 400 Bad Request
CIt accepts 1 and 0 only, so both true and yes are rejected
DIt coerces with Boolean(value), so every non-empty string becomes true

What does this achieve?

javascript
@Get(':id')
findOne(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {}
AIt generates a UUID when the parameter is missing
BIt converts the string into a binary UUID object for the database driver
CIt has no runtime effect unless a global ValidationPipe is also registered
DIt rejects any id that is not a valid v4 UUID with a 400, so malformed identifiers never reach the service or the database

What is the scope of this registration?

javascript
@UsePipes(new ValidationPipe({ whitelist: true }))
@Controller('cats')
export class CatsController {
  @Post() create(@Body() dto: CreateCatDto) {}
  @Put(':id') update(@Body() dto: UpdateCatDto) {}
}
AEvery handler in this controller, for every argument that has a metatype to validate — one declaration instead of repeating the pipe on each method
BOnly the first handler declared in the class
CEvery controller in the same module
DNothing; @UsePipes() is valid on methods only

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.