mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-26 04:27:54 +00:00
removed count from all entities
This commit is contained in:
@@ -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<void> {
|
||||
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;
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user