Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Joi for validation.
NestJS
import * as [1] from 'joi';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from 'express' or 'nestjs' instead of 'joi'.
Using 'class-validator' which is a different validation library.
✗ Incorrect
Joi is imported as a namespace to use its validation functions.
2fill in blank
mediumComplete the code to define a Joi schema for a username that is a required string.
NestJS
const schema = Joi.object({ username: Joi.[1]().required() }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
number() or boolean() instead of string().Forgetting to call
required() to make the field mandatory.✗ Incorrect
The username should be a string, so we use Joi.string().
3fill in blank
hardFix the error in the validation pipe setup by completing the missing property.
NestJS
app.useGlobalPipes(new ValidationPipe({ whitelist: [1] })); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting whitelist to false or null disables property filtering.
Leaving whitelist undefined means no filtering happens.
✗ Incorrect
Setting whitelist: true removes properties not in the DTO.
4fill in blank
hardFill both blanks to create a Joi schema for an email that is required and must be valid.
NestJS
const schema = Joi.object({ email: Joi.[1]().[2]() }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
email() instead of string() (email is a validator, not a type).Forgetting to add
required().✗ Incorrect
Email should be a string and required, so use string() and required().
5fill in blank
hardFill all three blanks to create a Joi schema for a password that is a required string with minimum length 8.
NestJS
const schema = Joi.object({ password: Joi.[1]().min([2]).[3]() }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
number() instead of string().Forgetting to call
required().Setting
min to a string instead of a number.✗ Incorrect
Password must be a string, at least 8 characters, and required.