0
0
NestJSframework~10 mins

Default value pipe in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the DefaultValuePipe from NestJS.

NestJS
import { [1] } from '@nestjs/common';
Drag options to blanks, or click blank then click option'
AValidationPipe
BParseIntPipe
CDefaultValuePipe
DUsePipes
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong pipe like ValidationPipe or ParseIntPipe.
Forgetting to import the pipe.
2fill in blank
medium

Complete the code to apply DefaultValuePipe with a default value of 'guest' to the 'username' query parameter.

NestJS
@Query('username', new [1]('guest')) username: string
Drag options to blanks, or click blank then click option'
ADefaultValuePipe
BValidationPipe
CParseBoolPipe
DParseIntPipe
Attempts:
3 left
💡 Hint
Common Mistakes
Using ParseIntPipe or ValidationPipe instead of DefaultValuePipe.
Not passing the default value as a constructor argument.
3fill in blank
hard

Fix the error in the code to correctly use DefaultValuePipe with a default value of 10 for the 'limit' query parameter.

NestJS
@Query('limit', new [1](10)) limit: number
Drag options to blanks, or click blank then click option'
AParseBoolPipe
BValidationPipe
CParseArrayPipe
DDefaultValuePipe
Attempts:
3 left
💡 Hint
Common Mistakes
Using pipes that do not accept default values like ParseBoolPipe.
Not wrapping the pipe with 'new'.
4fill in blank
hard

Fill both blanks to create a controller method that uses DefaultValuePipe to set a default page number of 1 and a default page size of 20.

NestJS
getItems(@Query('page', new [1](1)) page: number, @Query('size', new [2](20)) size: number) { return { page, size }; }
Drag options to blanks, or click blank then click option'
ADefaultValuePipe
BParseIntPipe
CValidationPipe
DParseBoolPipe
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different pipes for the two parameters.
Using pipes that do not accept default values.
5fill in blank
hard

Fill all three blanks to create a controller method that uses DefaultValuePipe and ParseIntPipe to set default values and parse integers for 'page', 'size', and 'sortOrder' query parameters.

NestJS
getData(@Query('page', new [1](1), new [2]()) page: number, @Query('size', new [3](10), new ParseIntPipe()) size: number, @Query('sortOrder', new DefaultValuePipe('asc')) sortOrder: string) { return { page, size, sortOrder }; }
Drag options to blanks, or click blank then click option'
ADefaultValuePipe
BParseIntPipe
CValidationPipe
DParseBoolPipe
Attempts:
3 left
💡 Hint
Common Mistakes
Using ParseIntPipe before DefaultValuePipe.
Not using DefaultValuePipe for default values.
Using ValidationPipe instead of ParseIntPipe.