Files
dmenu-api/src/modules/cart/dto/bulk-add-items.dto.ts
T
2025-12-15 23:07:50 +03:30

34 lines
906 B
TypeScript

import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsArray, ValidateNested, ArrayMinSize, IsNumber, Min, IsString } from 'class-validator';
import { Type } from 'class-transformer';
class AddItemToCartDto {
@ApiProperty({ description: 'Quantity of the food item', example: 1, minimum: 1 })
@IsNotEmpty()
@IsNumber()
@Min(1)
quantity!: number;
@ApiProperty({ description: 'Food ID' })
@IsNotEmpty()
@IsString()
foodId!: string;
}
export class BulkAddItemsToCartDto {
@ApiProperty({
description: 'Array of items to add to cart',
type: [AddItemToCartDto],
example: [
{ foodId: 'food-123', quantity: 2 },
{ foodId: 'food-456', quantity: 1 },
],
})
@IsNotEmpty()
@IsArray()
@ArrayMinSize(1, { message: 'At least one item is required' })
@ValidateNested({ each: true })
@Type(() => AddItemToCartDto)
items!: AddItemToCartDto[];
}