84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
import {
|
|
IsString,
|
|
IsArray,
|
|
IsNumber,
|
|
IsNotEmpty,
|
|
ArrayMinSize,
|
|
IsOptional,
|
|
Min,
|
|
ValidateNested,
|
|
} from 'class-validator';
|
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
import { Type } from 'class-transformer';
|
|
import { IAttachment } from '../interface/request.interface';
|
|
|
|
export class RequestItemDto {
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
fieldId: string;
|
|
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
value: string;
|
|
}
|
|
|
|
class AttachmentDto implements IAttachment {
|
|
@IsString()
|
|
type: string;
|
|
|
|
@IsString()
|
|
url: string;
|
|
}
|
|
|
|
export class CreateRequestItemDto {
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@ApiProperty()
|
|
productId: string;
|
|
|
|
@IsNumber()
|
|
@Min(1, { message: 'Quantity must be at least 1' })
|
|
@ApiProperty({ minimum: 1 })
|
|
quantity: number;
|
|
|
|
@ApiPropertyOptional({ type: [RequestItemDto], description: 'Product attribute field values' })
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => RequestItemDto)
|
|
attributes?: RequestItemDto[];
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsString()
|
|
description?: string;
|
|
|
|
@ApiPropertyOptional({ type: [AttachmentDto] })
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => AttachmentDto)
|
|
attachments?: IAttachment[];
|
|
}
|
|
|
|
export class CreateRequestDto {
|
|
@IsArray()
|
|
@ApiProperty({
|
|
isArray: true,
|
|
type: [CreateRequestItemDto],
|
|
example: [
|
|
{
|
|
productId: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
|
|
quantity: 100,
|
|
attributes: [{ fieldId: 'field_01', value: 'blue' }],
|
|
attachments: [{ type: 'image', url: 'https://example.com/photo.jpg' }],
|
|
description: 'توضیحات',
|
|
},
|
|
],
|
|
})
|
|
@IsNotEmpty()
|
|
@ArrayMinSize(1, { message: 'At least one item is required' })
|
|
@Type(() => CreateRequestItemDto)
|
|
items: CreateRequestItemDto[];
|
|
}
|