import { IsString, IsNotEmpty, IsOptional } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class CreateModuleDto {
@ApiProperty({ description: 'Field description' })
@IsString()
@IsNotEmpty()
name: string;
@ApiPropertyOptional({ description: 'Optional field' })
@IsString()
@IsOptional()
description?: string;
}
- Use
class-validator decorators
@IsString(), @IsNumber(), @IsEmail(), etc.
@IsNotEmpty() for required fields
@IsOptional() for optional fields
@Min(), @Max() for numeric ranges
@ApiProperty() for required fields
@ApiPropertyOptional() for optional fields
- Include
description in all fields
- Use
example when useful
- Use
class-transformer for transformations
@Transform() for custom transformations
@Exclude() to exclude fields from responses
- Name:
{Action}{Entity}Dto
- Request:
CreateLoanDto, UpdateUserDto
- Response:
LoanResponseDto, UserResponseDto
- File:
{action}-{entity}.dto.ts
@IsString()
@Matches(/^G[A-Z0-9]{55}$/, { message: 'Invalid Stellar wallet address' })
wallet: string;