import { IsString, IsInt, IsArray, IsNumber, IsNotEmpty, ArrayMinSize } from 'class-validator'; import { ApiPropertyOptional, ApiProperty, OmitType } from '@nestjs/swagger'; import { Type } from 'class-transformer'; export class CreateOrderItemDtoAsAdmin { @IsInt() @ApiProperty() productId: bigint; @ApiProperty() @IsNumber() quantity: number // TODO : find a way to save attribute and value @ApiProperty() @IsArray() attributesValues: string[] @ApiPropertyOptional({ example: 'توضیحات' }) @IsString() description: string @ApiPropertyOptional({ example: [] }) @IsArray() attachments: { url: string, type: string }[] @ApiProperty() @IsNumber() unitPrice: number @ApiProperty() @IsNumber() discount: number } export class CreateOrderItemAsUserDto extends OmitType(CreateOrderItemDtoAsAdmin, ['unitPrice', 'discount']) { } export class CreateOrderDto { @IsArray() @ApiProperty({ isArray: true, type: [CreateOrderItemAsUserDto], example: [ { productId: 1, quantity: 100, attributesValues: [], attachments: [ { url: '', type: '' } ], description: '' } ] }) @IsNotEmpty() @ArrayMinSize(1, { message: 'At least one item is required' }) @Type(() => CreateOrderItemAsUserDto) items: CreateOrderItemAsUserDto[]; }