mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
Merge pull request #300 from SyncrowIOT/fix-get-spaces-hierarchy-issue
remove duplicate issue
This commit is contained in:
@ -645,9 +645,9 @@ export class SpaceService {
|
|||||||
private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] {
|
private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] {
|
||||||
const map = new Map<string, SpaceEntity>();
|
const map = new Map<string, SpaceEntity>();
|
||||||
|
|
||||||
// Step 1: Create a map of spaces by UUID, without creating new instances
|
// Step 1: Create a map of spaces by UUID
|
||||||
spaces.forEach((space) => {
|
spaces.forEach((space: any) => {
|
||||||
map.set(space.uuid, space); // Use the existing space entity
|
map.set(space.uuid, { ...space, children: [] }); // Ensure children are reset
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 2: Organize the hierarchy
|
// Step 2: Organize the hierarchy
|
||||||
@ -656,13 +656,13 @@ export class SpaceService {
|
|||||||
if (space.parent && space.parent.uuid) {
|
if (space.parent && space.parent.uuid) {
|
||||||
const parent = map.get(space.parent.uuid);
|
const parent = map.get(space.parent.uuid);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (!parent.children) {
|
const child = map.get(space.uuid);
|
||||||
parent.children = [];
|
if (child && !parent.children.some((c) => c.uuid === child.uuid)) {
|
||||||
|
parent.children.push(child);
|
||||||
}
|
}
|
||||||
parent.children.push(space);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rootSpaces.push(space);
|
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user