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 {