mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +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[] {
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user