diff --git a/libs/common/src/modules/space-model/dtos/space-product-model.dto.ts b/libs/common/src/modules/space-model/dtos/space-product-model.dto.ts index 7952a23..aa6a3a3 100644 --- a/libs/common/src/modules/space-model/dtos/space-product-model.dto.ts +++ b/libs/common/src/modules/space-model/dtos/space-product-model.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsNotEmpty, IsNumber, IsString } from 'class-validator'; +import { IsNotEmpty, IsString } from 'class-validator'; import { SpaceProductItemModelDto } from './space-product-item-model.dto'; export class SpaceProductModelDto { @@ -7,10 +7,6 @@ export class SpaceProductModelDto { @IsNotEmpty() uuid: string; - @IsNumber() - @IsNotEmpty() - productCount: number; - @IsString() @IsNotEmpty() productUuid: string; diff --git a/libs/common/src/modules/space-model/dtos/subspace-model/subspace-product-model.dto.ts b/libs/common/src/modules/space-model/dtos/subspace-model/subspace-product-model.dto.ts index 4eebaae..c76d8d1 100644 --- a/libs/common/src/modules/space-model/dtos/subspace-model/subspace-product-model.dto.ts +++ b/libs/common/src/modules/space-model/dtos/subspace-model/subspace-product-model.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsNotEmpty, IsNumber, IsString } from 'class-validator'; +import { IsNotEmpty, IsString } from 'class-validator'; import { SubspaceProductItemModelDto } from './subspace-product-item-model.dto'; export class SubpaceProductModelDto { @@ -7,10 +7,6 @@ export class SubpaceProductModelDto { @IsNotEmpty() uuid: string; - @IsNumber() - @IsNotEmpty() - productCount: number; - @IsString() @IsNotEmpty() productUuid: string; diff --git a/libs/common/src/modules/space-model/entities/space-product-model.entity.ts b/libs/common/src/modules/space-model/entities/space-product-model.entity.ts index 9fdcd83..b520313 100644 --- a/libs/common/src/modules/space-model/entities/space-product-model.entity.ts +++ b/libs/common/src/modules/space-model/entities/space-product-model.entity.ts @@ -8,12 +8,6 @@ import { SpaceProductEntity } from '../../space/entities'; @Entity({ name: 'space-product-model' }) export class SpaceProductModelEntity extends AbstractEntity { - @Column({ - nullable: false, - type: 'int', - }) - productCount: number; - @ManyToOne( () => SpaceModelEntity, (spaceModel) => spaceModel.spaceProductModels, diff --git a/libs/common/src/modules/space-model/entities/subspace-model/subspace-product-model.entity.ts b/libs/common/src/modules/space-model/entities/subspace-model/subspace-product-model.entity.ts index 960c6fe..8aa53fb 100644 --- a/libs/common/src/modules/space-model/entities/subspace-model/subspace-product-model.entity.ts +++ b/libs/common/src/modules/space-model/entities/subspace-model/subspace-product-model.entity.ts @@ -8,12 +8,6 @@ import { SubspaceProductItemModelEntity } from './subspace-product-item-model.en @Entity({ name: 'subspace-product-model' }) export class SubspaceProductModelEntity extends AbstractEntity { - @Column({ - nullable: false, - type: 'int', - }) - productCount: number; - @Column({ nullable: false, default: false, diff --git a/libs/common/src/modules/space/dtos/space-product.dto.ts b/libs/common/src/modules/space/dtos/space-product.dto.ts index a57d29e..92f5f71 100644 --- a/libs/common/src/modules/space/dtos/space-product.dto.ts +++ b/libs/common/src/modules/space/dtos/space-product.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; +import { IsString, IsNotEmpty } from 'class-validator'; import { SpaceProductItemDto } from './space-product-item.dto'; export class SpaceProductModelDto { @@ -7,10 +7,6 @@ export class SpaceProductModelDto { @IsNotEmpty() uuid: string; - @IsNumber() - @IsNotEmpty() - productCount: number; - @IsString() @IsNotEmpty() productUuid: string; diff --git a/libs/common/src/modules/space/entities/space-product.entity.ts b/libs/common/src/modules/space/entities/space-product.entity.ts index c268302..ee2cb4f 100644 --- a/libs/common/src/modules/space/entities/space-product.entity.ts +++ b/libs/common/src/modules/space/entities/space-product.entity.ts @@ -21,12 +21,6 @@ export class SpaceProductEntity extends AbstractEntity { @JoinColumn({ name: 'product_uuid' }) product: ProductEntity; - @Column({ - nullable: false, - type: 'int', - }) - productCount: number; - @Column({ nullable: false, default: false, diff --git a/libs/common/src/modules/space/entities/subspace/subspace-product.entity.ts b/libs/common/src/modules/space/entities/subspace/subspace-product.entity.ts index 501f539..77cafa3 100644 --- a/libs/common/src/modules/space/entities/subspace/subspace-product.entity.ts +++ b/libs/common/src/modules/space/entities/subspace/subspace-product.entity.ts @@ -15,12 +15,6 @@ export class SubspaceProductEntity extends AbstractEntity }) public uuid: string; - @Column({ - nullable: false, - type: 'int', - }) - productCount: number; - @Column({ nullable: false, default: false, diff --git a/src/space-model/common/services/base-product-model.service.ts b/src/space-model/common/services/base-product-model.service.ts index c3230a3..6ff8d91 100644 --- a/src/space-model/common/services/base-product-model.service.ts +++ b/src/space-model/common/services/base-product-model.service.ts @@ -1,22 +1,8 @@ -import { HttpException, HttpStatus } from '@nestjs/common'; -import { CreateProductModelDto } from '../../dtos'; import { ProductService } from '../../../product/services'; export abstract class BaseProductModelService { constructor(private readonly productService: ProductService) {} - protected async validateProductCount( - dto: CreateProductModelDto, - ): Promise { - const productItemCount = dto.items.length; - if (dto.productCount !== productItemCount) { - throw new HttpException( - `Product count (${dto.productCount}) does not match the number of items (${productItemCount}) for product ID ${dto.productUuid}.`, - HttpStatus.BAD_REQUEST, - ); - } - } - protected async getProduct(productId: string) { const product = await this.productService.findOne(productId); return product.data; 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 0b4882e..b40e9d7 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 @@ -4,7 +4,6 @@ import { IsString, IsArray, ValidateNested, - IsInt, ArrayNotEmpty, } from 'class-validator'; import { Type } from 'class-transformer'; @@ -19,14 +18,6 @@ export class CreateProductModelDto { @IsString() productUuid: string; - @ApiProperty({ - description: 'Number of products in the model', - example: 3, - }) - @IsNotEmpty() - @IsInt() - productCount: number; - @ApiProperty({ description: 'Specific names for each product item', type: [CreateProductItemModelDto], 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 224330e..9310b46 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 @@ -1,24 +1,10 @@ import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; -import { - IsNotEmpty, - IsInt, - IsArray, - ArrayNotEmpty, - ValidateNested, -} from 'class-validator'; +import { IsArray, ArrayNotEmpty, ValidateNested } from 'class-validator'; import { BaseProductModelDto } from './base-product-model.dto'; import { ProductItemModelModificationDto } from '../product-item-model-dtos'; export class UpdateProductModelDto extends BaseProductModelDto { - @ApiProperty({ - description: 'Number of products to be modified in the model', - example: 3, - }) - @IsNotEmpty() - @IsInt() - productCount: number; - @ApiProperty({ description: 'Update product item', type: [ProductItemModelModificationDto], diff --git a/src/space-model/handlers/propate-subspace-handler.ts b/src/space-model/handlers/propate-subspace-handler.ts index 82431bd..d3ff2a1 100644 --- a/src/space-model/handlers/propate-subspace-handler.ts +++ b/src/space-model/handlers/propate-subspace-handler.ts @@ -189,14 +189,13 @@ export class PropogateSubspaceHandler const subspaceProduct = this.productRepository.create({ product: productModel.productModel.product, subspace, - productCount: productModel.productModel.productCount, model: productModel.productModel, }); const createdSubspaceProduct = await this.productRepository.save(subspaceProduct); this.logger.log( - `Product added to subspace ${subspace.id} with count ${createdSubspaceProduct.productCount}`, + `Product added to subspace ${subspace.id} with count ${createdSubspaceProduct.items.length}`, ); return createdSubspaceProduct; } diff --git a/src/space-model/services/space-product-model.service.ts b/src/space-model/services/space-product-model.service.ts index ccfa780..ba14317 100644 --- a/src/space-model/services/space-product-model.service.ts +++ b/src/space-model/services/space-product-model.service.ts @@ -27,13 +27,11 @@ export class SpaceProductModelService extends BaseProductModelService { try { const productModels = await Promise.all( spaceProductModelDtos.map(async (dto) => { - this.validateProductCount(dto); const product = await this.getProduct(dto.productUuid); return queryRunner.manager.create( this.spaceProductModelRepository.target, { product, - productCount: dto.productCount, spaceModel, }, ); diff --git a/src/space-model/services/subspace/subspace-product-model.service.ts b/src/space-model/services/subspace/subspace-product-model.service.ts index 9743aca..8b9d05f 100644 --- a/src/space-model/services/subspace/subspace-product-model.service.ts +++ b/src/space-model/services/subspace/subspace-product-model.service.ts @@ -41,13 +41,11 @@ export class SubspaceProductModelService extends BaseProductModelService { const productModels = await Promise.all( spaceProductModelDtos.map(async (dto) => { - this.validateProductCount(dto); const product = await this.getProduct(dto.productUuid); return queryRunner.manager.create( this.subpaceProductModelRepository.target, { product, - productCount: dto.productCount, subspaceModel, }, ); @@ -89,18 +87,6 @@ export class SubspaceProductModelService extends BaseProductModelService { try { for (const dto of dtos) { await this.findOne(dto.productModelUuid); - const newCount = dto.productCount; - if ( - dto.items.add.length + - dto.items.delete.length + - dto.items.delete.length !== - newCount - ) { - throw new HttpException( - `Invalid list of items`, - HttpStatus.BAD_REQUEST, - ); - } } } catch (error) {} } diff --git a/src/space/dtos/add.space.dto.ts b/src/space/dtos/add.space.dto.ts index dba8e92..7c10c59 100644 --- a/src/space/dtos/add.space.dto.ts +++ b/src/space/dtos/add.space.dto.ts @@ -30,12 +30,6 @@ export class ProductAssignmentDto { @IsNotEmpty() productId: string; - @ApiProperty({ - description: 'Number of items to assign for the product', - example: 3, - }) - count: number; - @ApiProperty({ description: 'Specific names for each product item', type: [CreateSpaceProductItemDto], diff --git a/src/space/services/space-products/space-products.service.ts b/src/space/services/space-products/space-products.service.ts index 2fe75cb..6c5f1bd 100644 --- a/src/space/services/space-products/space-products.service.ts +++ b/src/space/services/space-products/space-products.service.ts @@ -31,7 +31,6 @@ export class SpaceProductService { queryRunner.manager.create(SpaceProductEntity, { space: space, product: spaceProductModel.product, - productCount: spaceProductModel.productCount, spaceProductModel: spaceProductModel, }), ); @@ -150,16 +149,13 @@ export class SpaceProductService { ): Promise { const updatedProducts = []; - for (const { productId, count } of uniqueProducts) { + for (const { productId } of uniqueProducts) { productEntities.get(productId); const existingProduct = existingSpaceProducts.find( (spaceProduct) => spaceProduct.product.uuid === productId, ); - if (existingProduct && existingProduct.productCount !== count) { - existingProduct.productCount = count; - updatedProducts.push(existingProduct); - } + updatedProducts.push(existingProduct); } if (updatedProducts.length > 0) { @@ -180,13 +176,11 @@ export class SpaceProductService { for (const uniqueSpaceProduct of uniqueSpaceProducts) { const product = productEntities.get(uniqueSpaceProduct.productId); await this.getProduct(uniqueSpaceProduct.productId); - this.validateProductCount(uniqueSpaceProduct); newProducts.push( queryRunner.manager.create(SpaceProductEntity, { space, product, - productCount: uniqueSpaceProduct.count, }), ); } @@ -209,16 +203,6 @@ export class SpaceProductService { return newProducts; } - private validateProductCount(dto: ProductAssignmentDto) { - const productItemCount = dto.items.length; - if (dto.count !== productItemCount) { - throw new HttpException( - `Product count (${dto.count}) does not match the number of items (${productItemCount}) for product ID ${dto.productId}.`, - HttpStatus.BAD_REQUEST, - ); - } - } - async getProduct(productId: string): Promise { const product = await this.productService.findOne(productId); return product.data; diff --git a/src/space/services/subspace/subspace-product.service.ts b/src/space/services/subspace/subspace-product.service.ts index e789311..48852d7 100644 --- a/src/space/services/subspace/subspace-product.service.ts +++ b/src/space/services/subspace/subspace-product.service.ts @@ -64,7 +64,6 @@ export class SubspaceProductService { return { subspace, product: productModel.product, - productCount: productModel.productCount, model: productModel, }; } @@ -78,13 +77,10 @@ export class SubspaceProductService { try { const newSpaceProducts = await Promise.all( productDtos.map(async (dto) => { - this.validateProductCount(dto); - const product = await this.getProduct(dto.productId); return queryRunner.manager.create(SubspaceProductEntity, { subspace, product, - productCount: dto.count, }); }), ); @@ -116,13 +112,4 @@ export class SubspaceProductService { const product = await this.productService.findOne(productId); return product.data; } - - async validateProductCount(dto: ProductAssignmentDto) { - if (dto.count !== dto.items.length) { - throw new HttpException( - 'Producy item and count doesnot match', - HttpStatus.BAD_REQUEST, - ); - } - } }