mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 21:27:54 +00:00
added space model details to space
This commit is contained in:
@@ -17,7 +17,7 @@ export class CreateSpaceProductModelDto {
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
productId: string;
|
||||
productUuid: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Number of products in the model',
|
||||
|
||||
@@ -21,6 +21,12 @@ export class SpaceProductItemModelService {
|
||||
) {
|
||||
await this.validateTags(itemModelDtos, queryRunner, spaceModel);
|
||||
|
||||
if (!spaceProductModel) {
|
||||
throw new HttpException(
|
||||
'Space product model is required to create product items.',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
try {
|
||||
const productItems = itemModelDtos.map((dto) =>
|
||||
queryRunner.manager.create(this.spaceProductItemRepository.target, {
|
||||
|
||||
@@ -25,7 +25,7 @@ export class SpaceProductModelService {
|
||||
const productModels = await Promise.all(
|
||||
spaceProductModelDtos.map(async (dto) => {
|
||||
this.validateProductCount(dto);
|
||||
const product = await this.getProduct(dto.productId);
|
||||
const product = await this.getProduct(dto.productUuid);
|
||||
return queryRunner.manager.create(
|
||||
this.spaceProductModelRepository.target,
|
||||
{
|
||||
@@ -40,14 +40,15 @@ export class SpaceProductModelService {
|
||||
const savedProductModels = await queryRunner.manager.save(productModels);
|
||||
|
||||
await Promise.all(
|
||||
spaceProductModelDtos.map((dto, index) =>
|
||||
this.spaceProductItemModelService.createProdutItemModel(
|
||||
spaceProductModelDtos.map((dto, index) => {
|
||||
const savedModel = savedProductModels[index];
|
||||
return this.spaceProductItemModelService.createProdutItemModel(
|
||||
dto.items,
|
||||
savedProductModels[index],
|
||||
savedModel, // Pass the saved model
|
||||
spaceModel,
|
||||
queryRunner,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) {
|
||||
@@ -65,7 +66,7 @@ export class SpaceProductModelService {
|
||||
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.productId}.`,
|
||||
`Product count (${dto.productCount}) does not match the number of items (${productItemCount}) for product ID ${dto.productUuid}.`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user