finished return the spaces in get community

This commit is contained in:
faris Aljohari
2025-03-18 01:52:01 +03:00
parent 990bcffc2f
commit 9902b02700
5 changed files with 151 additions and 4 deletions

View File

@ -14,12 +14,14 @@ import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service
import { ProjectRepository } from '@app/common/modules/project/repositiories';
import { ORPHAN_COMMUNITY_NAME } from '@app/common/constants/orphan-constant';
import { Not } from 'typeorm';
import { SpaceService } from 'src/space/services';
@Injectable()
export class CommunityService {
constructor(
private readonly communityRepository: CommunityRepository,
private readonly projectRepository: ProjectRepository,
private readonly spaceService: SpaceService,
private readonly tuyaService: TuyaService,
) {}
@ -98,6 +100,27 @@ 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,
},
);
return {
...community,
spaces: spaces.data,
};
}),
);
baseResponseDto.data = communitiesWithSpaces;
return new PageResponse<CommunityDto>(
baseResponseDto,
paginationResponseDto,