mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +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 { IsPageRequestParam } from '../validators/is-page-request-param.validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsSizeRequestParam } from '../validators/is-size-request-param.validator';
|
import { IsSizeRequestParam } from '../validators/is-size-request-param.validator';
|
||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
import { parseToDate } from '../util/parseToDate';
|
import { parseToDate } from '../util/parseToDate';
|
||||||
|
import { BooleanValues } from '../constants/boolean-values.enum';
|
||||||
|
|
||||||
export class PaginationRequestGetListDto {
|
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()
|
@IsOptional()
|
||||||
@IsPageRequestParam({
|
@IsPageRequestParam({
|
||||||
message: 'Page must be bigger than 0',
|
message: 'Page must be bigger than 0',
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export interface TypeORMCustomModelFindAllQuery {
|
|||||||
where?: { [key: string]: unknown };
|
where?: { [key: string]: unknown };
|
||||||
select?: string[];
|
select?: string[];
|
||||||
includeDisable?: boolean | string;
|
includeDisable?: boolean | string;
|
||||||
|
includeSpaces?: boolean;
|
||||||
}
|
}
|
||||||
interface CustomFindAllQuery {
|
interface CustomFindAllQuery {
|
||||||
page?: number;
|
page?: number;
|
||||||
|
|||||||
@ -100,26 +100,29 @@ export class CommunityService {
|
|||||||
const { baseResponseDto, paginationResponseDto } =
|
const { baseResponseDto, paginationResponseDto } =
|
||||||
await customModel.findAll(pageable);
|
await customModel.findAll(pageable);
|
||||||
|
|
||||||
const communitiesWithSpaces = await Promise.all(
|
if (pageable.includeSpaces) {
|
||||||
baseResponseDto.data.map(async (community: CommunityDto) => {
|
const communitiesWithSpaces = await Promise.all(
|
||||||
const spaces = await this.spaceService.getSpacesHierarchyForCommunity(
|
baseResponseDto.data.map(async (community: CommunityDto) => {
|
||||||
{
|
const spaces =
|
||||||
communityUuid: community.uuid,
|
await this.spaceService.getSpacesHierarchyForCommunity(
|
||||||
projectUuid: param.projectUuid,
|
{
|
||||||
},
|
communityUuid: community.uuid,
|
||||||
{
|
projectUuid: param.projectUuid,
|
||||||
onlyWithDevices: false,
|
},
|
||||||
},
|
{
|
||||||
);
|
onlyWithDevices: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...community,
|
...community,
|
||||||
spaces: spaces.data,
|
spaces: spaces.data,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
baseResponseDto.data = communitiesWithSpaces;
|
baseResponseDto.data = communitiesWithSpaces;
|
||||||
|
}
|
||||||
|
|
||||||
return new PageResponse<CommunityDto>(
|
return new PageResponse<CommunityDto>(
|
||||||
baseResponseDto,
|
baseResponseDto,
|
||||||
|
|||||||
Reference in New Issue
Block a user