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

return tags name
This commit is contained in:
faris Aljohari
2025-03-10 15:41:43 +03:00
committed by GitHub

View File

@ -653,15 +653,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 // Step 1: Create a map of spaces by UUID, without creating new instances
spaces.forEach((space) => { spaces.forEach((space) => {
map.set( map.set(space.uuid, space); // Use the existing space entity
space.uuid,
this.spaceRepository.create({
...space,
children: [], // Add children if needed
}),
);
}); });
// Step 2: Organize the hierarchy // Step 2: Organize the hierarchy
@ -669,9 +663,14 @@ export class SpaceService {
spaces.forEach((space) => { spaces.forEach((space) => {
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);
parent?.children?.push(map.get(space.uuid)); if (parent) {
if (!parent.children) {
parent.children = [];
}
parent.children.push(space);
}
} else { } else {
rootSpaces.push(map.get(space.uuid)); rootSpaces.push(space);
} }
}); });