fixed delete space

This commit is contained in:
hannathkadher
2025-01-06 13:42:08 +04:00
parent c0c876c491
commit d719ad60f4
4 changed files with 26 additions and 21 deletions

View File

@ -19,7 +19,7 @@ import { SpaceEntity } from '@app/common/modules/space/entities';
import { generateRandomString } from '@app/common/helper/randomString';
import { SpaceLinkService } from './space-link';
import { SubSpaceService } from './subspace';
import { DataSource, Not, QueryRunner } from 'typeorm';
import { DataSource, QueryRunner } from 'typeorm';
import { ValidationService } from './space-validation.service';
import {
ORPHAN_COMMUNITY_NAME,
@ -171,25 +171,28 @@ export class SpaceService {
);
try {
// Get all spaces related to the community, including the parent-child relations
const spaces = await this.spaceRepository.find({
where: {
community: { uuid: communityUuid },
spaceName: Not(`${ORPHAN_SPACE_NAME}`),
disabled: false,
},
relations: [
'parent',
const spaces = await this.spaceRepository
.createQueryBuilder('space')
.leftJoinAndSelect('space.parent', 'parent')
.leftJoinAndSelect(
'space.children',
'children',
'incomingConnections',
'tags',
'tags.product',
'subspaces',
'subspaces.tags',
'subspaces.tags.product',
],
});
'children.disabled = :disabled',
{ disabled: false },
)
.leftJoinAndSelect('space.incomingConnections', 'incomingConnections')
.leftJoinAndSelect('space.tags', 'tags')
.leftJoinAndSelect('tags.product', 'tagProduct')
.leftJoinAndSelect('space.subspaces', 'subspaces')
.leftJoinAndSelect('subspaces.tags', 'subspaceTags')
.leftJoinAndSelect('subspaceTags.product', 'subspaceTagProduct')
.where('space.community_id = :communityUuid', { communityUuid })
.andWhere('space.spaceName != :orphanSpaceName', {
orphanSpaceName: ORPHAN_SPACE_NAME,
})
.andWhere('space.disabled = :disabled', { disabled: false })
.getMany();
// Organize spaces into a hierarchical structure
const spaceHierarchy = this.buildSpaceHierarchy(spaces);
return new SuccessResponseDto({