fix bug in create request
This commit is contained in:
@@ -1,15 +1,34 @@
|
||||
import {
|
||||
IsString,
|
||||
IsInt,
|
||||
IsArray,
|
||||
IsNumber,
|
||||
IsNotEmpty,
|
||||
ArrayMinSize,
|
||||
IsOptional,
|
||||
Min,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IAttachment, IField } from '../interface/request.interface';
|
||||
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()
|
||||
@@ -18,22 +37,27 @@ export class CreateRequestItemDto {
|
||||
productId: string;
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty()
|
||||
@Min(1, { message: 'Quantity must be at least 1' })
|
||||
@ApiProperty({ minimum: 1 })
|
||||
quantity: number;
|
||||
|
||||
@ApiPropertyOptional({ type: 'array', items: { type: 'object', properties: { fieldId: { type: 'number' }, value: { type: 'string' } } } })
|
||||
@ApiPropertyOptional({ type: [RequestItemDto], description: 'Product attribute field values' })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
attributes?: IField[];
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => RequestItemDto)
|
||||
attributes?: RequestItemDto[];
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@ApiPropertyOptional({ type: 'array', items: { type: 'object', properties: { type: { type: 'string' }, url: { type: 'string' } } } })
|
||||
@ApiPropertyOptional({ type: [AttachmentDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => AttachmentDto)
|
||||
attachments?: IAttachment[];
|
||||
}
|
||||
|
||||
@@ -46,8 +70,8 @@ export class CreateRequestDto {
|
||||
{
|
||||
productId: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
|
||||
quantity: 100,
|
||||
attributes: [{ fieldId: 1, value: 'blue' }],
|
||||
attachments: [{ url: '', type: 'image' }],
|
||||
attributes: [{ fieldId: 'field_01', value: 'blue' }],
|
||||
attachments: [{ type: 'image', url: 'https://example.com/photo.jpg' }],
|
||||
description: 'توضیحات',
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user