order
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
IsString
|
||||
} from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class AssignDesignerDto {
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
designerId: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IsArray, } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IField } from '../interface/order.interface';
|
||||
|
||||
export class CreatePrintFormDto {
|
||||
@ApiPropertyOptional({
|
||||
example: [{
|
||||
fieldId: 10, value: ''
|
||||
}]
|
||||
})
|
||||
@IsArray()
|
||||
printAttributes?: IField[]
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsNumber,
|
||||
Min,
|
||||
IsIn,
|
||||
IsEnum,
|
||||
IsDateString,
|
||||
IsArray,
|
||||
} from 'class-validator';
|
||||
import { Type, Transform } from 'class-transformer';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { OrderStatusEnum } from '../interface/order.interface';
|
||||
import { PaymentStatusEnum } from '../../payment/interface/payment';
|
||||
|
||||
const sortOrderOptions = ['asc', 'desc'] as const;
|
||||
type SortOrder = (typeof sortOrderOptions)[number];
|
||||
|
||||
export class FindOrderItemsDto {
|
||||
@ApiPropertyOptional({ default: 1, minimum: 1 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
page: number = 1;
|
||||
|
||||
@ApiPropertyOptional({ default: 10, minimum: 1 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
limit: number = 10;
|
||||
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
search?: string;
|
||||
|
||||
|
||||
@ApiPropertyOptional({ default: 'createdAt' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
orderBy: string = 'createdAt';
|
||||
|
||||
@ApiPropertyOptional({
|
||||
enum: sortOrderOptions,
|
||||
default: 'desc',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsIn(sortOrderOptions)
|
||||
order: SortOrder = 'desc';
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsNumber,
|
||||
Min,
|
||||
IsIn,
|
||||
IsEnum,
|
||||
IsDateString,
|
||||
IsArray,
|
||||
} from 'class-validator';
|
||||
import { Type, Transform } from 'class-transformer';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { OrderStatusEnum } from '../interface/order.interface';
|
||||
import { PaymentStatusEnum } from '../../payment/interface/payment';
|
||||
|
||||
const sortOrderOptions = ['asc', 'desc'] as const;
|
||||
type SortOrder = (typeof sortOrderOptions)[number];
|
||||
|
||||
export class FindOrdersDto {
|
||||
@ApiPropertyOptional({ default: 1, minimum: 1 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
page: number = 1;
|
||||
|
||||
@ApiPropertyOptional({ default: 10, minimum: 1 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
limit: number = 10;
|
||||
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'Filter by order statuses',
|
||||
enum: OrderStatusEnum,
|
||||
isArray: true,
|
||||
})
|
||||
@IsOptional()
|
||||
@Transform(({ value }) =>
|
||||
Array.isArray(value) ? value : value?.split(',')
|
||||
)
|
||||
@IsArray()
|
||||
@IsEnum(OrderStatusEnum, { each: true })
|
||||
statuses?: OrderStatusEnum[];
|
||||
|
||||
// @ApiPropertyOptional({ enum: PaymentStatusEnum })
|
||||
// @IsOptional()
|
||||
// @IsEnum(PaymentStatusEnum)
|
||||
// paymentStatus?: PaymentStatusEnum;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
search?: string;
|
||||
|
||||
@ApiPropertyOptional({ format: 'date-time' })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
from?: string;
|
||||
|
||||
@ApiPropertyOptional({ format: 'date-time' })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
to?: string;
|
||||
|
||||
@ApiPropertyOptional({ default: 'createdAt' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
orderBy: string = 'createdAt';
|
||||
|
||||
@ApiPropertyOptional({
|
||||
enum: sortOrderOptions,
|
||||
default: 'desc',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsIn(sortOrderOptions)
|
||||
order: SortOrder = 'desc';
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateOrderItemAsUserDto, CreateOrderItemDtoAsAdmin } from './create-order.dto';
|
||||
|
||||
export class UpdateOrderItemDtoAsUser extends PartialType(CreateOrderItemAsUserDto) { }
|
||||
export class UpdateOrderItemDtoAsAdmin extends PartialType(CreateOrderItemDtoAsAdmin) { }
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger';
|
||||
import { CreateOrderAsAdminDto, CreateOrderItemDtoAsAdmin } from './create-order.dto';
|
||||
import { IsNumber } from 'class-validator';
|
||||
|
||||
export class UpdateOrderAsAdminDto extends PartialType(OmitType(CreateOrderAsAdminDto, 'items' as any)) {
|
||||
@ApiProperty()
|
||||
items: UpdateOrCreateOrderItem[]
|
||||
}
|
||||
|
||||
export class UpdateOrCreateOrderItem extends CreateOrderItemDtoAsAdmin {
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
id: string
|
||||
}
|
||||
Reference in New Issue
Block a user