mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 09:37:56 +00:00
update product model
This commit is contained in:
@@ -159,7 +159,7 @@ export class SubspaceProductItemModelService extends BaseProductItemService {
|
||||
}
|
||||
return productItemModels;
|
||||
} catch (error) {
|
||||
this.handleException(error, 'Failed to modify SpaceModels.');
|
||||
this.handleException(error, 'Failed to modify Product Item Models.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
SubspaceModelEntity,
|
||||
SubspaceProductModelEntity,
|
||||
SubspaceProductModelRepository,
|
||||
} from '@app/common/modules/space-model';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { SubspaceProductItemModelService } from './subspace-product-item-model.service';
|
||||
import { CreateProductModelDto } from '../../dtos';
|
||||
import { QueryRunner } from 'typeorm';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
|
||||
import { SubspaceProductItemModelService } from './subspace-product-item-model.service';
|
||||
import {
|
||||
CreateProductModelDto,
|
||||
ProductModelModificationDto,
|
||||
UpdateProductModelDto,
|
||||
} from '../../dtos';
|
||||
import { BaseProductModelService } from '../../common';
|
||||
import { ProductService } from 'src/product/services';
|
||||
import {
|
||||
IModifiedProductModelsInterface,
|
||||
ProductModelInterface,
|
||||
} from '../../interfaces';
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceProductModelService extends BaseProductModelService {
|
||||
@@ -25,7 +35,7 @@ export class SubspaceProductModelService extends BaseProductModelService {
|
||||
spaceModel: SpaceModelEntity,
|
||||
subspaceModel: SubspaceModelEntity,
|
||||
queryRunner: QueryRunner,
|
||||
) {
|
||||
): Promise<ProductModelInterface[]> {
|
||||
try {
|
||||
if (!spaceProductModelDtos?.length) return;
|
||||
|
||||
@@ -59,7 +69,7 @@ export class SubspaceProductModelService extends BaseProductModelService {
|
||||
return {
|
||||
productModel: savedModel,
|
||||
productItemModels,
|
||||
};
|
||||
} as ProductModelInterface;
|
||||
}),
|
||||
);
|
||||
return newProductModels;
|
||||
@@ -74,4 +84,63 @@ export class SubspaceProductModelService extends BaseProductModelService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async updateSubspaceProductModels(dtos: UpdateProductModelDto[]) {
|
||||
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) {}
|
||||
}
|
||||
|
||||
async modifySubspaceProductModels(
|
||||
dto: ProductModelModificationDto,
|
||||
spaceModel: SpaceModelEntity,
|
||||
subspaceModel: SubspaceModelEntity,
|
||||
queryRunner: QueryRunner,
|
||||
) {
|
||||
const productItemModels: IModifiedProductModelsInterface = {};
|
||||
try {
|
||||
productItemModels.add = await this.createSubspaceProductModels(
|
||||
dto.add,
|
||||
spaceModel,
|
||||
subspaceModel,
|
||||
queryRunner,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) {
|
||||
throw error;
|
||||
}
|
||||
throw new HttpException(
|
||||
'Failed to modify Subspace product model',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async findOne(uuid: string): Promise<SubspaceProductModelEntity> {
|
||||
const productModel = await this.subpaceProductModelRepository.findOne({
|
||||
where: {
|
||||
uuid,
|
||||
},
|
||||
});
|
||||
if (!productModel)
|
||||
throw new HttpException(
|
||||
`Subspace Product model with uuid ${uuid} not found`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
return productModel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user