clear subspace tags allocation

This commit is contained in:
faris Aljohari
2025-03-03 21:06:22 +03:00
parent 2b6f6be149
commit 4e43954175
2 changed files with 58 additions and 0 deletions

View File

@ -505,4 +505,39 @@ export class SubspaceProductAllocationService {
: HttpStatus.INTERNAL_SERVER_ERROR,
);
}
async clearAllAllocations(subspaceUuids: string[], queryRunner: QueryRunner) {
try {
await queryRunner.manager
.createQueryBuilder()
.delete()
.from('subspace_product_tags')
.where('subspace_product_allocation_uuid IN (:...allocationUuids)', {
allocationUuids: await queryRunner.manager
.createQueryBuilder(SubspaceProductAllocationEntity, 'allocation')
.select('allocation.uuid')
.where('allocation.subspaceUuid IN (:...subspaceUuids)', {
subspaceUuids,
})
.getRawMany()
.then((results) => results.map((r) => r.allocation_uuid)),
})
.execute();
await queryRunner.manager
.createQueryBuilder()
.delete()
.from(SubspaceProductAllocationEntity)
.where('subspaceUuid IN (:...subspaceUuids)', { subspaceUuids })
.execute();
} catch (error) {
throw new HttpException(
error instanceof HttpException
? error.message
: 'An unexpected error occurred while clearing allocations',
error instanceof HttpException
? error.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}

View File

@ -574,4 +574,27 @@ export class SubSpaceService {
extractTagsFromSubspace(addSubspaceDto: AddSubspaceDto[]): ProcessTagDto[] {
return addSubspaceDto.flatMap((subspace) => subspace.tags || []);
}
async clearSubspaces(subspaceUuids: string[], queryRunner: QueryRunner) {
try {
await queryRunner.manager.update(
SubspaceEntity,
{ uuid: In(subspaceUuids) },
{ disabled: true },
);
await this.subspaceProductAllocationService.clearAllAllocations(
subspaceUuids,
queryRunner,
);
} catch (error) {
throw new HttpException(
error instanceof HttpException
? error.message
: 'An unexpected error occurred while clearing subspaces',
error instanceof HttpException
? error.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}