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

View File

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

View File

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

View File

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