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