From f9878ff272036bb7a5b82bf10dc24bfdc40daae3 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 11 Mar 2025 12:19:26 +0300 Subject: [PATCH] remove duplicate issue --- src/space/services/space.service.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index f72c0ca..505f00f 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -645,9 +645,9 @@ export class SpaceService { private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] { const map = new Map(); - // 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 } });