create-product.dto.ts
nest.js/03-advanced/code/products/dto/create-product.dto.ts
import {
IsString,
IsNotEmpty,
IsNumber,
Min,
IsOptional,
IsUrl,
MinLength,
MaxLength,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class CreateProductDto {
@ApiProperty({ example: 'Laptop', description: 'Product name' })
@IsString()
@IsNotEmpty()
@MinLength(3)
@MaxLength(100)
name: string;
@ApiProperty({ example: 'High-performance laptop', description: 'Product description' })
@IsString()
@IsOptional()
@MaxLength(500)
description?: string;
@ApiProperty({ example: 999.99, description: 'Product price' })
@IsNumber()
@Min(0)
price: number;
@ApiPropertyOptional({ example: 10, description: 'Product stock quantity' })
@IsNumber()
@Min(0)
@IsOptional()
stock?: number;
@ApiPropertyOptional({ example: 'https://example.com/image.jpg', description: 'Product image URL' })
@IsUrl()
@IsOptional()
imageUrl?: string;
@ApiPropertyOptional({ example: 'electronics', description: 'Product category' })
@IsString()
@IsOptional()
category?: string;
}
관련 글
app.controller.ts
app.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.controller.ts).
글 읽기 →app.module.ts
app.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.module.ts).
글 읽기 →app.service.ts
app.service.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.service.ts).
글 읽기 →main.ts
main.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/main.ts).
글 읽기 →todos.controller.ts
todos.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.controller.ts).
글 읽기 →todos.module.ts
todos.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.module.ts).
글 읽기 →