146 lines
3.2 KiB
TypeScript
146 lines
3.2 KiB
TypeScript
import {
|
|
IsString,
|
|
IsInt, IsArray, IsNumber,
|
|
IsNotEmpty,
|
|
ArrayMinSize,
|
|
IsOptional,
|
|
IsBoolean,
|
|
IsEnum,
|
|
IsDateString
|
|
} from 'class-validator';
|
|
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
|
import { Type } from 'class-transformer';
|
|
import { IAttachment, IField, OrderItemStatusEnum } from '../interface/order.interface';
|
|
|
|
|
|
export class CreateOrderItemAsUserDto {
|
|
@IsString()
|
|
@ApiProperty()
|
|
productId: string;
|
|
|
|
@ApiProperty()
|
|
@IsNumber()
|
|
quantity: number
|
|
|
|
@ApiProperty({ enum: OrderItemStatusEnum })
|
|
@IsEnum(() => OrderItemStatusEnum)
|
|
status: OrderItemStatusEnum
|
|
|
|
@ApiProperty()
|
|
@IsArray()
|
|
attributes: IField[]
|
|
|
|
@ApiPropertyOptional({ example: 'توضیحات' })
|
|
@IsString()
|
|
description: string
|
|
|
|
@ApiPropertyOptional({ example: [] })
|
|
@IsArray()
|
|
attachments: { url: string, type: string }[]
|
|
|
|
|
|
}
|
|
|
|
export class CreateOrderItemDtoAsAdmin extends CreateOrderItemAsUserDto {
|
|
// @ApiPropertyOptional({ example: [] })
|
|
// @IsArray()
|
|
// printAttributes?: IField[]
|
|
|
|
// @ApiPropertyOptional({ example: [] })
|
|
// @IsArray()
|
|
// printAttachments?: IAttachment[]
|
|
|
|
@IsInt()
|
|
@ApiProperty()
|
|
designerId: string;
|
|
|
|
@ApiProperty()
|
|
@IsNumber()
|
|
unitPrice: number
|
|
|
|
@ApiProperty()
|
|
@IsNumber()
|
|
discount: number
|
|
|
|
@ApiPropertyOptional()
|
|
@IsString()
|
|
adminDescription: string
|
|
|
|
@ApiPropertyOptional()
|
|
@IsDateString()
|
|
confirmedAt: string
|
|
|
|
}
|
|
|
|
export class CreateOrderAsUSerDto {
|
|
@IsArray()
|
|
@ApiProperty({
|
|
isArray: true, type: [CreateOrderItemAsUserDto], example: [
|
|
{
|
|
productId: 'sd4',
|
|
quantity: 100,
|
|
attributes: [
|
|
{
|
|
attributeId: 1,
|
|
value: 'string | boolean| number'
|
|
}
|
|
],
|
|
attachments: [
|
|
{ url: '', type: '' }
|
|
],
|
|
description: ''
|
|
}
|
|
]
|
|
})
|
|
@IsNotEmpty()
|
|
@ArrayMinSize(1, { message: 'At least one item is required' })
|
|
@Type(() => CreateOrderItemAsUserDto)
|
|
items: CreateOrderItemAsUserDto[];
|
|
}
|
|
|
|
|
|
export class CreateOrderAsAdminDto {
|
|
@ApiProperty({ example: '' })
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
userId: string
|
|
|
|
@IsArray()
|
|
@ApiProperty({
|
|
isArray: true, type: [CreateOrderItemDtoAsAdmin], example: [
|
|
{
|
|
productId: 1,
|
|
designerId: '',
|
|
attachments: [{ url: '', type: '' }],
|
|
quantity: 100,
|
|
attributes: [{ fieldId: 10, value: 'blue' }],
|
|
unitPrice: 150000,
|
|
discount: 20000,
|
|
adminDescription: '',
|
|
description: 'توضیحات کاربر',
|
|
|
|
}
|
|
]
|
|
})
|
|
@IsNotEmpty()
|
|
@ArrayMinSize(1, { message: 'At least one product is required' })
|
|
@Type(() => CreateOrderItemDtoAsAdmin)
|
|
items: CreateOrderItemDtoAsAdmin[];
|
|
|
|
|
|
@ApiProperty({})
|
|
@IsString()
|
|
@IsOptional()
|
|
paymentMethod: string
|
|
|
|
@ApiProperty({})
|
|
@IsBoolean()
|
|
enableTax: boolean
|
|
|
|
@ApiProperty({})
|
|
@IsInt()
|
|
estimatedDays: number
|
|
|
|
|
|
}
|