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(
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,

View File

@ -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 ?? [],