Merge pull request #282 from SyncrowIOT/bugfix/space-allocation

This commit is contained in:
hannathkadher
2025-03-06 13:10:08 +04:00
committed by GitHub
2 changed files with 16 additions and 14 deletions

View File

@ -25,6 +25,7 @@ export class SubspaceModelProductAllocationService {
async createProductAllocations( async createProductAllocations(
subspaceModel: SubspaceModelEntity, subspaceModel: SubspaceModelEntity,
spaceModel: SpaceModelEntity,
tags: NewTagEntity[], tags: NewTagEntity[],
queryRunner?: QueryRunner, queryRunner?: QueryRunner,
spaceAllocationsToExclude?: SpaceModelProductAllocationEntity[], spaceAllocationsToExclude?: SpaceModelProductAllocationEntity[],
@ -34,23 +35,24 @@ export class SubspaceModelProductAllocationService {
for (const tag of tags) { for (const tag of tags) {
// Step 1: Check if this specific tag is already allocated at the space level // Step 1: Check if this specific tag is already allocated at the space level
const existingTagInSpaceModel = await (queryRunner const existingTagInSpaceModel = await (queryRunner
? queryRunner.manager.findOne(SpaceModelProductAllocationEntity, { ? queryRunner.manager.findOne(SpaceModelProductAllocationEntity, {
where: { where: {
product: tag.product, spaceModel: {
spaceModel: subspaceModel.spaceModel, // Check at the space level uuid: spaceModel.uuid,
}, // Check at the space level
tags: { uuid: tag.uuid }, // Check for the specific tag tags: { uuid: tag.uuid }, // Check for the specific tag
}, },
relations: ['tags'], relations: ['tags'],
}) })
: this.spaceModelAllocationRepository.findOne({ : this.spaceModelAllocationRepository.findOne({
where: { where: {
product: tag.product, spaceModel: {
spaceModel: subspaceModel.spaceModel, uuid: spaceModel.uuid,
},
tags: { uuid: tag.uuid }, tags: { uuid: tag.uuid },
}, },
relations: ['tags'], relations: ['tags', 'product'],
})); }));
const isExcluded = spaceAllocationsToExclude?.some( const isExcluded = spaceAllocationsToExclude?.some(
@ -171,7 +173,7 @@ export class SubspaceModelProductAllocationService {
return allocations; return allocations;
} catch (error) { } catch (error) {
throw new HttpException( 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, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} }
@ -456,7 +458,7 @@ export class SubspaceModelProductAllocationService {
spaceModel: { uuid: spaceModel.uuid }, spaceModel: { uuid: spaceModel.uuid },
tags: { uuid: deletedTag.tagUuid }, tags: { uuid: deletedTag.tagUuid },
}, },
relations: ['tags', 'subspace'], relations: ['tags', 'product'],
}, },
); );
@ -472,6 +474,7 @@ export class SubspaceModelProductAllocationService {
// Create new product allocations // Create new product allocations
await this.createProductAllocations( await this.createProductAllocations(
subspaceModel.subspaceModel, subspaceModel.subspaceModel,
spaceModel,
processedTags, processedTags,
queryRunner, queryRunner,
spaceAllocationToExclude, spaceAllocationToExclude,

View File

@ -51,6 +51,7 @@ export class SubSpaceModelService {
await this.productAllocationService.createProductAllocations( await this.productAllocationService.createProductAllocations(
subspaceModel, subspaceModel,
spaceModel,
processedTags, processedTags,
queryRunner, queryRunner,
); );
@ -311,15 +312,13 @@ export class SubSpaceModelService {
{ where: { uuid: dto.uuid } }, { where: { uuid: dto.uuid } },
); );
if ( if (existingSubspace) {
existingSubspace &&
existingSubspace.subspaceName !== dto.subspaceName
) {
if (existingSubspace.subspaceName !== dto.subspaceName) { if (existingSubspace.subspaceName !== dto.subspaceName) {
await this.checkDuplicateNames(dto.subspaceName, spaceModel.uuid); 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({ updatedSubspaces.push({
subspaceModel: existingSubspace, subspaceModel: existingSubspace,
tags: dto.tags ?? [], tags: dto.tags ?? [],