From e18214c717e775bca1db5f7049718656302e36a4 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Fri, 20 Dec 2024 08:45:52 +0400 Subject: [PATCH] defined product model dto --- src/space-model/dtos/index.ts | 2 +- .../base-product-item-model.dto.ts | 12 +++++++ .../create-product-item-model.dto.ts} | 0 .../delete-product-item-model.dto.ts | 3 ++ .../dtos/product-item-model-dtos/index.ts | 4 +++ .../product-item-model-modification.ts | 34 +++++++++++++++++++ .../update-prodct-item-model.dto.ts | 13 +++++++ .../create-product-model.dto.ts | 2 +- .../update-product-model.dto.ts | 11 +++--- 9 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 src/space-model/dtos/product-item-model-dtos/base-product-item-model.dto.ts rename src/space-model/dtos/{create-space-product-item-model.dto.ts => product-item-model-dtos/create-product-item-model.dto.ts} (100%) create mode 100644 src/space-model/dtos/product-item-model-dtos/delete-product-item-model.dto.ts create mode 100644 src/space-model/dtos/product-item-model-dtos/index.ts create mode 100644 src/space-model/dtos/product-item-model-dtos/product-item-model-modification.ts create mode 100644 src/space-model/dtos/product-item-model-dtos/update-prodct-item-model.dto.ts diff --git a/src/space-model/dtos/index.ts b/src/space-model/dtos/index.ts index 20aaebc..045d4aa 100644 --- a/src/space-model/dtos/index.ts +++ b/src/space-model/dtos/index.ts @@ -1,5 +1,5 @@ export * from './create-space-model.dto'; -export * from './create-space-product-item-model.dto'; +export * from './product-item-model-dtos'; export * from './product-model-dtos'; export * from './project-param.dto'; export * from './update-space-model.dto'; diff --git a/src/space-model/dtos/product-item-model-dtos/base-product-item-model.dto.ts b/src/space-model/dtos/product-item-model-dtos/base-product-item-model.dto.ts new file mode 100644 index 0000000..dc01713 --- /dev/null +++ b/src/space-model/dtos/product-item-model-dtos/base-product-item-model.dto.ts @@ -0,0 +1,12 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsString } from 'class-validator'; + +export class BaseProductItemModelDto { + @ApiProperty({ + description: 'ID of the product item model', + example: 'product-item-uuid', + }) + @IsNotEmpty() + @IsString() + productModelUuid: string; +} diff --git a/src/space-model/dtos/create-space-product-item-model.dto.ts b/src/space-model/dtos/product-item-model-dtos/create-product-item-model.dto.ts similarity index 100% rename from src/space-model/dtos/create-space-product-item-model.dto.ts rename to src/space-model/dtos/product-item-model-dtos/create-product-item-model.dto.ts diff --git a/src/space-model/dtos/product-item-model-dtos/delete-product-item-model.dto.ts b/src/space-model/dtos/product-item-model-dtos/delete-product-item-model.dto.ts new file mode 100644 index 0000000..971a0d0 --- /dev/null +++ b/src/space-model/dtos/product-item-model-dtos/delete-product-item-model.dto.ts @@ -0,0 +1,3 @@ +import { BaseProductItemModelDto } from './base-product-item-model.dto'; + +export class DeleteProductItemModelDto extends BaseProductItemModelDto {} diff --git a/src/space-model/dtos/product-item-model-dtos/index.ts b/src/space-model/dtos/product-item-model-dtos/index.ts new file mode 100644 index 0000000..5225122 --- /dev/null +++ b/src/space-model/dtos/product-item-model-dtos/index.ts @@ -0,0 +1,4 @@ +export * from './create-product-item-model.dto'; +export * from './update-prodct-item-model.dto'; +export * from './delete-product-item-model.dto'; +export * from './product-item-model-modification' \ No newline at end of file diff --git a/src/space-model/dtos/product-item-model-dtos/product-item-model-modification.ts b/src/space-model/dtos/product-item-model-dtos/product-item-model-modification.ts new file mode 100644 index 0000000..04ca2d6 --- /dev/null +++ b/src/space-model/dtos/product-item-model-dtos/product-item-model-modification.ts @@ -0,0 +1,34 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsArray, ValidateNested, IsOptional } from 'class-validator'; + +import { CreateProductItemModelDto } from './create-product-item-model.dto'; +import { UpdateProductItemModelDto } from './update-prodct-item-model.dto'; +import { DeleteProductItemModelDto } from './delete-product-item-model.dto'; + +export class ProductItemModelModificationDto { + @IsArray() + @ApiProperty({ + description: 'Create the product item model ', + type: [CreateProductItemModelDto], + }) + @ValidateNested({ each: true }) + @IsOptional() + add?: CreateProductItemModelDto[]; + + @IsArray() + @ApiProperty({ + description: 'Update the product item model ', + type: [UpdateProductItemModelDto], + }) + @ValidateNested({ each: true }) + @IsOptional() + update?: UpdateProductItemModelDto[]; + + @IsArray() + @ApiProperty({ + description: 'Delete the product item model ', + type: [DeleteProductItemModelDto], + }) + @IsOptional() + delete?: DeleteProductItemModelDto[]; +} diff --git a/src/space-model/dtos/product-item-model-dtos/update-prodct-item-model.dto.ts b/src/space-model/dtos/product-item-model-dtos/update-prodct-item-model.dto.ts new file mode 100644 index 0000000..ef88432 --- /dev/null +++ b/src/space-model/dtos/product-item-model-dtos/update-prodct-item-model.dto.ts @@ -0,0 +1,13 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsString } from 'class-validator'; +import { BaseProductItemModelDto } from './base-product-item-model.dto'; + +export class UpdateProductItemModelDto extends BaseProductItemModelDto { + @ApiProperty({ + description: 'Specific name for the product item', + example: 'Light 1', + }) + @IsNotEmpty() + @IsString() + tag: string; +} diff --git a/src/space-model/dtos/product-model-dtos/create-product-model.dto.ts b/src/space-model/dtos/product-model-dtos/create-product-model.dto.ts index 947fc59..0b4882e 100644 --- a/src/space-model/dtos/product-model-dtos/create-product-model.dto.ts +++ b/src/space-model/dtos/product-model-dtos/create-product-model.dto.ts @@ -8,7 +8,7 @@ import { ArrayNotEmpty, } from 'class-validator'; import { Type } from 'class-transformer'; -import { CreateProductItemModelDto } from '../create-space-product-item-model.dto'; +import { CreateProductItemModelDto } from '../product-item-model-dtos/create-product-item-model.dto'; export class CreateProductModelDto { @ApiProperty({ diff --git a/src/space-model/dtos/product-model-dtos/update-product-model.dto.ts b/src/space-model/dtos/product-model-dtos/update-product-model.dto.ts index 0f0d64d..60e7baf 100644 --- a/src/space-model/dtos/product-model-dtos/update-product-model.dto.ts +++ b/src/space-model/dtos/product-model-dtos/update-product-model.dto.ts @@ -2,14 +2,13 @@ import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { IsNotEmpty, - IsString, IsInt, IsArray, ArrayNotEmpty, ValidateNested, } from 'class-validator'; -import { CreateProductItemModelDto } from '../create-space-product-item-model.dto'; import { BaseProductModelDto } from './base-product-model.dto'; +import { ProductItemModelModificationDto } from '../product-item-model-dtos'; export class UpdateProductModelDto extends BaseProductModelDto { @ApiProperty({ @@ -21,12 +20,12 @@ export class UpdateProductModelDto extends BaseProductModelDto { productCount: number; @ApiProperty({ - description: 'Specific names for each product item', - type: [CreateProductItemModelDto], + description: 'Update product item', + type: [ProductItemModelModificationDto], }) @IsArray() @ArrayNotEmpty() @ValidateNested({ each: true }) - @Type(() => CreateProductItemModelDto) - items: CreateProductItemModelDto[]; + @Type(() => ProductItemModelModificationDto) + items: ProductItemModelModificationDto[]; }