finished edit the response

This commit is contained in:
faris Aljohari
2025-03-06 13:03:56 +03:00
parent 5e6c7bef9e
commit f7848a7394

View File

@ -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<BaseResponseDto> {
const { communityUuid, spaceUuid, projectUuid } = params;
try {