mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:54:55 +00:00
clear space tags allocation
This commit is contained in:
@ -37,6 +37,7 @@ import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
import { ProcessTagDto } from 'src/tags/dtos';
|
||||
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
||||
import { SubspaceProductAllocationService } from './subspace/subspace-product-allocation.service';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subspace.entity';
|
||||
@Injectable()
|
||||
export class SpaceService {
|
||||
constructor(
|
||||
@ -379,8 +380,35 @@ export class SpaceService {
|
||||
spaceName: ORPHAN_SPACE_NAME,
|
||||
},
|
||||
});
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
await this.disableSpace(space, orphanSpace);
|
||||
try {
|
||||
await this.spaceProductAllocationService.clearAllAllocations(
|
||||
spaceUuid,
|
||||
queryRunner,
|
||||
);
|
||||
|
||||
const subspaces = await queryRunner.manager.find(SubspaceEntity, {
|
||||
where: { space: { uuid: spaceUuid } },
|
||||
});
|
||||
|
||||
const subspaceUuids = subspaces.map((subspace) => subspace.uuid);
|
||||
|
||||
if (subspaceUuids.length > 0) {
|
||||
await this.subSpaceService.clearSubspaces(subspaceUuids, queryRunner);
|
||||
}
|
||||
|
||||
await this.disableSpace(space, orphanSpace);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Space with ID ${spaceUuid} successfully deleted`,
|
||||
|
||||
Reference in New Issue
Block a user