fixed allocating tag from subspace to space

This commit is contained in:
hannathkadher
2025-03-06 20:54:51 +04:00
parent 1f18f50923
commit a68f4c1847
4 changed files with 23 additions and 10 deletions

View File

@ -192,7 +192,7 @@ export class SpaceModelProductAllocationService {
modifySubspaceModels,
spaces,
),
this.processDeleteActions(filteredDtos, queryRunner),
this.processDeleteActions(filteredDtos, queryRunner, spaceModel),
]);
} catch (error) {
throw this.handleError(error, 'Error while updating product allocations');
@ -297,6 +297,7 @@ export class SpaceModelProductAllocationService {
private async processDeleteActions(
dtos: ModifyTagModelDto[],
queryRunner: QueryRunner,
spaceModel: SpaceModelEntity,
): Promise<SpaceModelProductAllocationEntity[]> {
try {
if (!dtos || dtos.length === 0) {
@ -312,7 +313,12 @@ export class SpaceModelProductAllocationService {
const allocationsToUpdate = await queryRunner.manager.find(
SpaceModelProductAllocationEntity,
{
where: { tags: { uuid: In(tagUuidsToDelete) } },
where: {
tags: { uuid: In(tagUuidsToDelete) },
spaceModel: {
uuid: spaceModel.uuid,
},
},
relations: ['tags'],
},
);

View File

@ -243,17 +243,19 @@ export class SubspaceModelProductAllocationService {
.delete()
.from('subspace_model_product_tags')
.where(
'subspace_model_product_allocation_id NOT IN ' +
'subspace_model_product_allocation_uuid NOT IN (' +
queryRunner.manager
.createQueryBuilder()
.select('uuid')
.select('allocation.uuid')
.from(SubspaceModelProductAllocationEntity, 'allocation')
.getQuery(),
.getQuery() +
')',
)
.execute();
return deletedAllocations;
} catch (error) {
console.log(error);
throw this.handleError(error, `Failed to delete tags in subspace model`);
}
}

View File

@ -191,7 +191,7 @@ export class SpaceProductAllocationService {
modifySubspace,
),
this.processDeleteActions(dtos, queryRunner),
this.processDeleteActions(dtos, queryRunner, space),
]);
} catch (error) {
throw this.handleError(error, 'Error while updating product allocations');
@ -200,6 +200,7 @@ export class SpaceProductAllocationService {
private async processDeleteActions(
dtos: ModifyTagDto[],
queryRunner: QueryRunner,
space: SpaceEntity,
): Promise<SpaceProductAllocationEntity[]> {
try {
if (!dtos || dtos.length === 0) {
@ -215,7 +216,10 @@ export class SpaceProductAllocationService {
const allocationsToUpdate = await queryRunner.manager.find(
SpaceProductAllocationEntity,
{
where: { tags: { uuid: In(tagUuidsToDelete) } },
where: {
tags: { uuid: In(tagUuidsToDelete) },
space: { uuid: space.uuid },
},
relations: ['tags'],
},
);

View File

@ -359,12 +359,13 @@ export class SubspaceProductAllocationService {
.delete()
.from('subspace_product_tags')
.where(
'subspace_product_allocation_id NOT IN ' +
'subspace_product_allocation_uuid NOT IN ' +
queryRunner.manager
.createQueryBuilder()
.select('uuid')
.select('allocation.uuid')
.from(SubspaceProductAllocationEntity, 'allocation')
.getQuery(),
.getQuery() +
')',
)
.execute();