mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-27 02:37:54 +00:00
removed count from all entities
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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<SpaceProductEntity[]> {
|
||||
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<ProductEntity> {
|
||||
const product = await this.productService.findOne(productId);
|
||||
return product.data;
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user