mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +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, {
|
@OneToOne(() => DeviceEntity, (device) => device.tag, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
|
@JoinColumn({ name: 'device_id' })
|
||||||
device: DeviceEntity;
|
device: DeviceEntity;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import { SpaceEntity } from '@app/common/modules/space/entities';
|
|||||||
import { generateRandomString } from '@app/common/helper/randomString';
|
import { generateRandomString } from '@app/common/helper/randomString';
|
||||||
import { SpaceLinkService } from './space-link';
|
import { SpaceLinkService } from './space-link';
|
||||||
import { SubSpaceService } from './subspace';
|
import { SubSpaceService } from './subspace';
|
||||||
import { DataSource, Not, QueryRunner } from 'typeorm';
|
import { DataSource, QueryRunner } from 'typeorm';
|
||||||
import { ValidationService } from './space-validation.service';
|
import { ValidationService } from './space-validation.service';
|
||||||
import {
|
import {
|
||||||
ORPHAN_COMMUNITY_NAME,
|
ORPHAN_COMMUNITY_NAME,
|
||||||
@ -171,25 +171,28 @@ export class SpaceService {
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
// Get all spaces related to the community, including the parent-child relations
|
// Get all spaces related to the community, including the parent-child relations
|
||||||
const spaces = await this.spaceRepository.find({
|
const spaces = await this.spaceRepository
|
||||||
where: {
|
.createQueryBuilder('space')
|
||||||
community: { uuid: communityUuid },
|
.leftJoinAndSelect('space.parent', 'parent')
|
||||||
spaceName: Not(`${ORPHAN_SPACE_NAME}`),
|
.leftJoinAndSelect(
|
||||||
disabled: false,
|
'space.children',
|
||||||
},
|
|
||||||
relations: [
|
|
||||||
'parent',
|
|
||||||
'children',
|
'children',
|
||||||
'incomingConnections',
|
'children.disabled = :disabled',
|
||||||
'tags',
|
{ disabled: false },
|
||||||
'tags.product',
|
)
|
||||||
'subspaces',
|
.leftJoinAndSelect('space.incomingConnections', 'incomingConnections')
|
||||||
'subspaces.tags',
|
.leftJoinAndSelect('space.tags', 'tags')
|
||||||
'subspaces.tags.product',
|
.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);
|
const spaceHierarchy = this.buildSpaceHierarchy(spaces);
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
return new SuccessResponseDto({
|
||||||
|
@ -138,7 +138,7 @@ export class TagService {
|
|||||||
);
|
);
|
||||||
return { message: 'Tags deleted successfully', tagUuids };
|
return { message: 'Tags deleted successfully', tagUuids };
|
||||||
} catch (error) {
|
} 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) {
|
async deleteUserSpace(spaceUuid: string) {
|
||||||
try {
|
try {
|
||||||
await this.userSpaceRepository
|
await this.userSpaceRepository
|
||||||
.createQueryBuilder()
|
.createQueryBuilder('userSpace')
|
||||||
|
.leftJoin('userSpace.space', 'space')
|
||||||
.delete()
|
.delete()
|
||||||
.where('spaceUuid = :spaceUuid', { spaceUuid })
|
.where('space.uuid = :spaceUuid', { spaceUuid })
|
||||||
.execute();
|
.execute();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error deleting user-space associations: ${error.message}`);
|
console.error(`Error deleting user-space associations: ${error.message}`);
|
||||||
|
Reference in New Issue
Block a user