Complete the code to use ParseIntPipe to convert the route parameter to a number.
import { Controller, Get, Param, [1] } from '@nestjs/common'; @Controller('items') export class ItemsController { @Get(':id') getItem(@Param('id', [1]) id: number) { return `Item id is ${id}`; } }
The ParseIntPipe converts the route parameter id from string to number automatically.
Complete the code to use ParseBoolPipe to convert the query parameter to a boolean.
import { Controller, Get, Query, [1] } from '@nestjs/common'; @Controller('flags') export class FlagsController { @Get() getFlag(@Query('active', [1]) active: boolean) { return `Flag active is ${active}`; } }
The ParseBoolPipe converts the query parameter active from string to boolean automatically.
Fix the error in the code by choosing the correct pipe to parse the 'count' parameter as an integer.
import { Controller, Get, Param, [1] } from '@nestjs/common'; @Controller('counts') export class CountsController { @Get(':count') getCount(@Param('count', [1]) count: number) { return `Count is ${count}`; } }
The ParseIntPipe correctly converts the 'count' parameter to a number, fixing the error.
Fill both blanks to create a controller method that parses 'id' as an integer and 'enabled' as a boolean.
import { Controller, Get, Param, Query, [1], [2] } from '@nestjs/common'; @Controller('settings') export class SettingsController { @Get(':id') getSetting( @Param('id', [1]) id: number, @Query('enabled', [2]) enabled: boolean ) { return `Setting ${id} is ${enabled ? 'enabled' : 'disabled'}`; } }
Use ParseIntPipe to convert 'id' to a number and ParseBoolPipe to convert 'enabled' to a boolean.
Fill all three blanks to parse 'userId' as an integer, 'isAdmin' as a boolean, and 'page' as an integer.
import { Controller, Get, Param, Query, [1], [2], [3] } from '@nestjs/common'; @Controller('users') export class UsersController { @Get(':userId') getUser( @Param('userId', [1]) userId: number, @Query('isAdmin', [2]) isAdmin: boolean, @Query('page', [3]) page: number ) { return `User ${userId}, Admin: ${isAdmin}, Page: ${page}`; } }
Use ParseIntPipe for 'userId' and 'page' to convert to numbers, and ParseBoolPipe for 'isAdmin'.