mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
finished edit the response
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user