added space model details to space

This commit is contained in:
hannathkadher
2024-12-11 16:45:09 +04:00
parent bbd40253b8
commit a2ee7a0001
4 changed files with 73 additions and 19 deletions
@@ -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,
);
}