mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Merge pull request #297 from SyncrowIOT/fix-get-spaces-issue
return tags name
This commit is contained in:
@ -653,15 +653,9 @@ export class SpaceService {
|
||||
private buildSpaceHierarchy(spaces: SpaceEntity[]): 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) => {
|
||||
map.set(
|
||||
space.uuid,
|
||||
this.spaceRepository.create({
|
||||
...space,
|
||||
children: [], // Add children if needed
|
||||
}),
|
||||
);
|
||||
map.set(space.uuid, space); // Use the existing space entity
|
||||
});
|
||||
|
||||
// Step 2: Organize the hierarchy
|
||||
@ -669,9 +663,14 @@ export class SpaceService {
|
||||
spaces.forEach((space) => {
|
||||
if (space.parent && 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 {
|
||||
rootSpaces.push(map.get(space.uuid));
|
||||
rootSpaces.push(space);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user