add includeSpaces in the query param

This commit is contained in:
faris Aljohari
2025-03-18 10:17:29 +03:00
parent 9902b02700
commit 39ac2e6860
3 changed files with 36 additions and 19 deletions

View File

@ -100,26 +100,29 @@ export class CommunityService {
const { baseResponseDto, paginationResponseDto } =
await customModel.findAll(pageable);
const communitiesWithSpaces = await Promise.all(
baseResponseDto.data.map(async (community: CommunityDto) => {
const spaces = await this.spaceService.getSpacesHierarchyForCommunity(
{
communityUuid: community.uuid,
projectUuid: param.projectUuid,
},
{
onlyWithDevices: false,
},
);
if (pageable.includeSpaces) {
const communitiesWithSpaces = await Promise.all(
baseResponseDto.data.map(async (community: CommunityDto) => {
const spaces =
await this.spaceService.getSpacesHierarchyForCommunity(
{
communityUuid: community.uuid,
projectUuid: param.projectUuid,
},
{
onlyWithDevices: false,
},
);
return {
...community,
spaces: spaces.data,
};
}),
);
return {
...community,
spaces: spaces.data,
};
}),
);
baseResponseDto.data = communitiesWithSpaces;
baseResponseDto.data = communitiesWithSpaces;
}
return new PageResponse<CommunityDto>(
baseResponseDto,