mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
finished edit the response
This commit is contained in:
@ -275,11 +275,11 @@ export class SpaceService {
|
|||||||
|
|
||||||
const spaces = await queryBuilder.getMany();
|
const spaces = await queryBuilder.getMany();
|
||||||
|
|
||||||
const spaceHierarchy = this.buildSpaceHierarchy(spaces);
|
const transformedSpaces = spaces.map(this.transformSpace);
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
return new SuccessResponseDto({
|
||||||
message: `Spaces in community ${communityUuid} successfully fetched in hierarchy`,
|
message: `Spaces in community ${communityUuid} successfully fetched in hierarchy`,
|
||||||
data: onlyWithDevices ? spaces : spaceHierarchy,
|
data: onlyWithDevices ? spaces : transformedSpaces,
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} 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> {
|
async findOne(params: GetSpaceParam): Promise<BaseResponseDto> {
|
||||||
const { communityUuid, spaceUuid, projectUuid } = params;
|
const { communityUuid, spaceUuid, projectUuid } = params;
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user