order item
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
IsString, IsOptional, IsBoolean,
|
||||
IsInt, Min, IsArray, IsNumber,
|
||||
IsString,
|
||||
IsInt, IsArray, IsNumber,
|
||||
IsNotEmpty,
|
||||
ArrayMinSize
|
||||
} from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { ApiPropertyOptional, ApiProperty, OmitType } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class CreateOrderItemDto {
|
||||
export class CreateOrderItemDtoAsAdmin {
|
||||
|
||||
@IsInt()
|
||||
@ApiProperty()
|
||||
@@ -28,12 +28,24 @@ export class CreateOrderItemDto {
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
attachments: { url: string, type: string }[]
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
unitPrice: number
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
discount: number
|
||||
|
||||
}
|
||||
|
||||
export class CreateOrderItemAsUserDto extends OmitType(CreateOrderItemDtoAsAdmin, ['unitPrice', 'discount']) { }
|
||||
|
||||
|
||||
export class CreateOrderDto {
|
||||
@IsArray()
|
||||
@ApiProperty({
|
||||
isArray: true, type: [CreateOrderItemDto], example: [
|
||||
isArray: true, type: [CreateOrderItemAsUserDto], example: [
|
||||
{
|
||||
productId: 1,
|
||||
quantity: 100,
|
||||
@@ -47,7 +59,7 @@ export class CreateOrderDto {
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@ArrayMinSize(1, { message: 'At least one item is required' })
|
||||
@Type(() => CreateOrderItemDto)
|
||||
items: CreateOrderItemDto[];
|
||||
@Type(() => CreateOrderItemAsUserDto)
|
||||
items: CreateOrderItemAsUserDto[];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateOrderItemDto } from './create-order.dto';
|
||||
import { CreateOrderItemAsUserDto } from './create-order.dto';
|
||||
|
||||
export class UpdateOrderItemDto extends PartialType(CreateOrderItemDto) { }
|
||||
export class UpdateOrderItemDto extends PartialType(CreateOrderItemAsUserDto) { }
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ export class NewItemDto {
|
||||
|
||||
}
|
||||
|
||||
export class UpdateNewOrderDto {
|
||||
export class UpdateOrderDto {
|
||||
@IsArray()
|
||||
@ApiProperty({
|
||||
isArray: true, type: [ItemDto], example: [
|
||||
|
||||
Reference in New Issue
Block a user