0
0
NestJSframework~10 mins

Nested DTO validation 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 validation decorator for nested objects in NestJS.

NestJS
import { [1] } from 'class-validator';
Drag options to blanks, or click blank then click option'
AValidateNested
BIsString
CIsNumber
DIsNotEmpty
Attempts:
3 left
💡 Hint
Common Mistakes
Using IsString or IsNumber which validate primitive types, not nested objects.
2fill in blank
medium

Complete the code to apply nested validation on the 'address' property inside a DTO.

NestJS
export class UserDto {
  @[1]()
  address: AddressDto;
}
Drag options to blanks, or click blank then click option'
AIsNotEmpty
BIsString
CValidateNested
DIsArray
Attempts:
3 left
💡 Hint
Common Mistakes
Using IsString which only validates strings, not objects.
Forgetting to use ValidateNested for nested DTOs.
3fill in blank
hard

Fix the error in the code to ensure nested DTO validation works correctly with class-transformer.

NestJS
export class UserDto {
  @ValidateNested()
  @[1](() => AddressDto)
  address: AddressDto;
}
Drag options to blanks, or click blank then click option'
AType
BTransform
CExpose
DExclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using Transform which is for custom transformations, not type hinting.
Omitting the Type decorator causes nested validation to fail.
4fill in blank
hard

Fill both blanks to define a nested DTO with validation decorators for its properties.

NestJS
export class AddressDto {
  @[1]()
  street: string;

  @[2]()
  city: string;
}
Drag options to blanks, or click blank then click option'
AIsString
BIsNumber
CIsNotEmpty
DIsBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using IsNumber or IsBoolean for string fields.
Forgetting to check that city is not empty.
5fill in blank
hard

Fill all three blanks to create a nested DTO with validation and type transformation.

NestJS
import { [1] } from 'class-transformer';
import { [2], ValidateNested } from 'class-validator';

export class ProfileDto {
  @ValidateNested()
  @[3](() => UserDto)
  user: UserDto;
}
Drag options to blanks, or click blank then click option'
AType
BIsString
CValidateNested
DIsNotEmpty
Attempts:
3 left
💡 Hint
Common Mistakes
Not importing Type causes nested validation to fail.
Confusing IsString with Type decorator.