mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
fixed delete space
This commit is contained in:
@ -48,5 +48,6 @@ export class TagEntity extends AbstractEntity<TagDto> {
|
||||
@OneToOne(() => DeviceEntity, (device) => device.tag, {
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'device_id' })
|
||||
device: DeviceEntity;
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -138,7 +138,7 @@ export class TagService {
|
||||
);
|
||||
return { message: 'Tags deleted successfully', tagUuids };
|
||||
} catch (error) {
|
||||
throw this.handleUnexpectedError('Failed to update tags', error);
|
||||
throw this.handleUnexpectedError('Failed to delete tags', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,9 +152,10 @@ export class UserSpaceService {
|
||||
async deleteUserSpace(spaceUuid: string) {
|
||||
try {
|
||||
await this.userSpaceRepository
|
||||
.createQueryBuilder()
|
||||
.createQueryBuilder('userSpace')
|
||||
.leftJoin('userSpace.space', 'space')
|
||||
.delete()
|
||||
.where('spaceUuid = :spaceUuid', { spaceUuid })
|
||||
.where('space.uuid = :spaceUuid', { spaceUuid })
|
||||
.execute();
|
||||
} catch (error) {
|
||||
console.error(`Error deleting user-space associations: ${error.message}`);
|
||||
|
Reference in New Issue
Block a user