From f7848a73949c964c9c1537df91ab75d5f03bbacf Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Thu, 6 Mar 2025 13:03:56 +0300 Subject: [PATCH] finished edit the response --- src/space/services/space.service.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index 11a94e8..4b9cfc8 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -275,11 +275,11 @@ export class SpaceService { const spaces = await queryBuilder.getMany(); - const spaceHierarchy = this.buildSpaceHierarchy(spaces); + const transformedSpaces = spaces.map(this.transformSpace); return new SuccessResponseDto({ message: `Spaces in community ${communityUuid} successfully fetched in hierarchy`, - data: onlyWithDevices ? spaces : spaceHierarchy, + data: onlyWithDevices ? spaces : transformedSpaces, statusCode: HttpStatus.OK, }); } catch (error) { @@ -290,6 +290,28 @@ export class SpaceService { } } + private transformSpace(space) { + const { productAllocations, subspaces, ...restSpace } = space; + + const tags = productAllocations.flatMap((pa) => pa.tags); + + const transformedSubspaces = subspaces.map((subspace) => { + const { + productAllocations: subspaceProductAllocations, + ...restSubspace + } = subspace; + const subspaceTags = subspaceProductAllocations.flatMap((pa) => pa.tags); + return { + ...restSubspace, + tags: subspaceTags, + }; + }); + return { + ...restSpace, + tags, + subspaces: transformedSubspaces, + }; + } async findOne(params: GetSpaceParam): Promise { const { communityUuid, spaceUuid, projectUuid } = params; try {