Merge pull request #300 from SyncrowIOT/fix-get-spaces-hierarchy-issue

remove duplicate issue
This commit is contained in:
faris Aljohari
2025-03-11 12:20:52 +03:00
committed by GitHub

View File

@ -645,9 +645,9 @@ export class SpaceService {
private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] {
const map = new Map<string, SpaceEntity>();
// Step 1: Create a map of spaces by UUID, without creating new instances
spaces.forEach((space) => {
map.set(space.uuid, space); // Use the existing space entity
// Step 1: Create a map of spaces by UUID
spaces.forEach((space: any) => {
map.set(space.uuid, { ...space, children: [] }); // Ensure children are reset
});
// Step 2: Organize the hierarchy
@ -656,13 +656,13 @@ export class SpaceService {
if (space.parent && space.parent.uuid) {
const parent = map.get(space.parent.uuid);
if (parent) {
if (!parent.children) {
parent.children = [];
const child = map.get(space.uuid);
if (child && !parent.children.some((c) => c.uuid === child.uuid)) {
parent.children.push(child);
}
parent.children.push(space);
}
} else {
rootSpaces.push(space);
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
}
});