mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
add includeSpaces in the query param
This commit is contained in:
@ -1,11 +1,24 @@
|
||||
import { IsDate, IsOptional } from 'class-validator';
|
||||
import { IsBoolean, IsDate, IsOptional } from 'class-validator';
|
||||
import { IsPageRequestParam } from '../validators/is-page-request-param.validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsSizeRequestParam } from '../validators/is-size-request-param.validator';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { parseToDate } from '../util/parseToDate';
|
||||
import { BooleanValues } from '../constants/boolean-values.enum';
|
||||
|
||||
export class PaginationRequestGetListDto {
|
||||
@ApiProperty({
|
||||
example: true,
|
||||
description: 'include spaces',
|
||||
required: false,
|
||||
default: false,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform((value) => {
|
||||
return value.obj.includeSpaces === BooleanValues.TRUE;
|
||||
})
|
||||
public includeSpaces?: boolean = false;
|
||||
@IsOptional()
|
||||
@IsPageRequestParam({
|
||||
message: 'Page must be bigger than 0',
|
||||
|
@ -16,6 +16,7 @@ export interface TypeORMCustomModelFindAllQuery {
|
||||
where?: { [key: string]: unknown };
|
||||
select?: string[];
|
||||
includeDisable?: boolean | string;
|
||||
includeSpaces?: boolean;
|
||||
}
|
||||
interface CustomFindAllQuery {
|
||||
page?: number;
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user