diff --git a/src/space-model/services/subspace/subspace-model-product-allocation.service.ts b/src/space-model/services/subspace/subspace-model-product-allocation.service.ts index ef69f41..0005e5c 100644 --- a/src/space-model/services/subspace/subspace-model-product-allocation.service.ts +++ b/src/space-model/services/subspace/subspace-model-product-allocation.service.ts @@ -25,6 +25,7 @@ export class SubspaceModelProductAllocationService { async createProductAllocations( subspaceModel: SubspaceModelEntity, + spaceModel: SpaceModelEntity, tags: NewTagEntity[], queryRunner?: QueryRunner, spaceAllocationsToExclude?: SpaceModelProductAllocationEntity[], @@ -34,23 +35,24 @@ export class SubspaceModelProductAllocationService { for (const tag of tags) { // Step 1: Check if this specific tag is already allocated at the space level - const existingTagInSpaceModel = await (queryRunner ? queryRunner.manager.findOne(SpaceModelProductAllocationEntity, { where: { - product: tag.product, - spaceModel: subspaceModel.spaceModel, // Check at the space level + spaceModel: { + uuid: spaceModel.uuid, + }, // Check at the space level tags: { uuid: tag.uuid }, // Check for the specific tag }, relations: ['tags'], }) : this.spaceModelAllocationRepository.findOne({ where: { - product: tag.product, - spaceModel: subspaceModel.spaceModel, + spaceModel: { + uuid: spaceModel.uuid, + }, tags: { uuid: tag.uuid }, }, - relations: ['tags'], + relations: ['tags', 'product'], })); const isExcluded = spaceAllocationsToExclude?.some( @@ -171,7 +173,7 @@ export class SubspaceModelProductAllocationService { return allocations; } catch (error) { throw new HttpException( - 'An unexpected error occurred while creating subspace product allocations', + `An unexpected error occurred while creating subspace product allocations ${error}`, HttpStatus.INTERNAL_SERVER_ERROR, ); } @@ -456,7 +458,7 @@ export class SubspaceModelProductAllocationService { spaceModel: { uuid: spaceModel.uuid }, tags: { uuid: deletedTag.tagUuid }, }, - relations: ['tags', 'subspace'], + relations: ['tags', 'product'], }, ); @@ -472,6 +474,7 @@ export class SubspaceModelProductAllocationService { // Create new product allocations await this.createProductAllocations( subspaceModel.subspaceModel, + spaceModel, processedTags, queryRunner, spaceAllocationToExclude, diff --git a/src/space-model/services/subspace/subspace-model.service.ts b/src/space-model/services/subspace/subspace-model.service.ts index f072354..666ace4 100644 --- a/src/space-model/services/subspace/subspace-model.service.ts +++ b/src/space-model/services/subspace/subspace-model.service.ts @@ -51,6 +51,7 @@ export class SubSpaceModelService { await this.productAllocationService.createProductAllocations( subspaceModel, + spaceModel, processedTags, queryRunner, ); @@ -311,15 +312,13 @@ export class SubSpaceModelService { { where: { uuid: dto.uuid } }, ); - if ( - existingSubspace && - existingSubspace.subspaceName !== dto.subspaceName - ) { + if (existingSubspace) { if (existingSubspace.subspaceName !== dto.subspaceName) { await this.checkDuplicateNames(dto.subspaceName, spaceModel.uuid); + existingSubspace.subspaceName = dto.subspaceName; + await queryRunner.manager.save(existingSubspace); } - existingSubspace.subspaceName = dto.subspaceName; - await queryRunner.manager.save(existingSubspace); + updatedSubspaces.push({ subspaceModel: existingSubspace, tags: dto.tags ?? [],