Complete the code to define a basic DTO class with a single string property.
export class CreateUserDto { [1] name: string; }
The readonly keyword is used in DTO classes to make properties immutable after creation, which is a common pattern in NestJS DTOs.
Complete the code to import the class-validator decorator for string validation.
import { [1] } from 'class-validator'; export class CreateUserDto { readonly name: string; }
The IsString decorator validates that the property is a string, which is important for DTO input validation.
Fix the error in the DTO property decorator to validate a non-empty string.
import { IsString, [1] } from 'class-validator'; export class CreateUserDto { @IsString() @[1]() readonly name: string; }
IsOptional which allows empty values.The IsNotEmpty decorator ensures the string is not empty, which is a common validation for required fields.
Fill both blanks to create a DTO class with a numeric age property that must be positive.
import { IsPositive, [1] } from 'class-validator'; export class CreateUserDto { readonly name: string; @[2]() @IsPositive() readonly age: number; }
The IsNumber decorator validates the property is a number, and IsPositive ensures it is greater than zero.
Fill all three blanks to create a DTO class with a required email string property validated for email format.
import { IsString, [1], [2] } from 'class-validator'; export class CreateUserDto { @IsString() @IsEmail() @[3]() readonly email: string; }
IsOptional which allows missing emails.IsEmail validates the email format, and IsNotEmpty ensures the email is provided and not empty.