All quizzesEasy
Pipes, Guards & Interceptors — Series 3
Preview — 3 of 10 questions
What does this pipe do?
javascript
enum Status { Active = 'active', Archived = 'archived' }
@Get()
findAll(@Query('status', new ParseEnumPipe(Status)) status: Status) {}AIt converts the string to the enum's numeric index
BIt checks the incoming value against the enum's members and rejects anything else with a 400, so the handler can rely on status being one of the declared values
CIt returns the enum's default member when the value is unrecognised
DIt only works with numeric enums
What does the client receive?
javascript
@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {}
// GET /cats/abcA200 with id set to NaN
B500, because the conversion throws inside the handler
C422 Unprocessable Entity
D400 Bad Request with a message naming the failed validation — the pipe throws BadRequestException, which the exception layer turns into a standard error response
What has to happen for the handler to run?
javascript
@UseGuards(AuthGuard, RolesGuard, QuotaGuard)
@Post() create() {}AAll three must allow the request: guards run in declaration order and the first one to return false or throw stops the chain, so the remaining guards never execute
BAt least one must allow the request; guards are combined with OR
CThey run in parallel and the majority decides
DOnly the last guard's result is considered
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.