mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Merge pull request #319 from SyncrowIOT/SP-1322
added search for spaces
This commit is contained in:
13
libs/common/src/dto/pagination-with-search.request.dto.ts
Normal file
13
libs/common/src/dto/pagination-with-search.request.dto.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsOptional } from 'class-validator';
|
||||||
|
import { PaginationRequestGetListDto } from './pagination.request.dto';
|
||||||
|
|
||||||
|
export class PaginationRequestWithSearchGetListDto extends PaginationRequestGetListDto {
|
||||||
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
name: 'search',
|
||||||
|
required: false,
|
||||||
|
description: 'Search for community or space name',
|
||||||
|
})
|
||||||
|
search?: string;
|
||||||
|
}
|
@ -18,6 +18,12 @@ export interface TypeORMCustomModelFindAllQuery {
|
|||||||
includeDisable?: boolean | string;
|
includeDisable?: boolean | string;
|
||||||
includeSpaces?: boolean;
|
includeSpaces?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExtendedTypeORMCustomModelFindAllQuery
|
||||||
|
extends TypeORMCustomModelFindAllQuery {
|
||||||
|
search?: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface CustomFindAllQuery {
|
interface CustomFindAllQuery {
|
||||||
page?: number;
|
page?: number;
|
||||||
size?: number;
|
size?: number;
|
||||||
|
@ -17,10 +17,10 @@ import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
|||||||
// import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
// import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import { PaginationRequestGetListDto } from '@app/common/dto/pagination.request.dto';
|
|
||||||
import { ProjectParam } from '../dtos';
|
import { ProjectParam } from '../dtos';
|
||||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
import { PaginationRequestWithSearchGetListDto } from '@app/common/dto/pagination-with-search.request.dto';
|
||||||
|
|
||||||
@ApiTags('Community Module')
|
@ApiTags('Community Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -70,7 +70,7 @@ export class CommunityController {
|
|||||||
@Get()
|
@Get()
|
||||||
async getCommunities(
|
async getCommunities(
|
||||||
@Param() param: ProjectParam,
|
@Param() param: ProjectParam,
|
||||||
@Query() query: PaginationRequestGetListDto,
|
@Query() query: PaginationRequestWithSearchGetListDto,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
return this.communityService.getCommunities(param, query);
|
return this.communityService.getCommunities(param, query);
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ import { AddCommunityDto, GetCommunityParams, ProjectParam } from '../dtos';
|
|||||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import {
|
import {
|
||||||
|
ExtendedTypeORMCustomModelFindAllQuery,
|
||||||
TypeORMCustomModel,
|
TypeORMCustomModel,
|
||||||
TypeORMCustomModelFindAllQuery,
|
|
||||||
} from '@app/common/models/typeOrmCustom.model';
|
} from '@app/common/models/typeOrmCustom.model';
|
||||||
import { PageResponse } from '@app/common/dto/pagination.response.dto';
|
import { PageResponse } from '@app/common/dto/pagination.response.dto';
|
||||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||||
@ -13,7 +13,7 @@ import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
import { ORPHAN_COMMUNITY_NAME } from '@app/common/constants/orphan-constant';
|
import { ORPHAN_COMMUNITY_NAME } from '@app/common/constants/orphan-constant';
|
||||||
import { Not } from 'typeorm';
|
import { ILike, Not } from 'typeorm';
|
||||||
import { SpaceService } from 'src/space/services';
|
import { SpaceService } from 'src/space/services';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -84,7 +84,7 @@ export class CommunityService {
|
|||||||
|
|
||||||
async getCommunities(
|
async getCommunities(
|
||||||
param: ProjectParam,
|
param: ProjectParam,
|
||||||
pageable: Partial<TypeORMCustomModelFindAllQuery>,
|
pageable: Partial<ExtendedTypeORMCustomModelFindAllQuery>,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
try {
|
try {
|
||||||
const project = await this.validateProject(param.projectUuid);
|
const project = await this.validateProject(param.projectUuid);
|
||||||
@ -95,6 +95,9 @@ export class CommunityService {
|
|||||||
name: Not(`${ORPHAN_COMMUNITY_NAME}-${project.name}`),
|
name: Not(`${ORPHAN_COMMUNITY_NAME}-${project.name}`),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (pageable.search) {
|
||||||
|
pageable.where = { name: ILike(`%${pageable.search}%`) };
|
||||||
|
}
|
||||||
const customModel = TypeORMCustomModel(this.communityRepository);
|
const customModel = TypeORMCustomModel(this.communityRepository);
|
||||||
|
|
||||||
const { baseResponseDto, paginationResponseDto } =
|
const { baseResponseDto, paginationResponseDto } =
|
||||||
@ -111,6 +114,7 @@ export class CommunityService {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
onlyWithDevices: false,
|
onlyWithDevices: false,
|
||||||
|
search: pageable.search,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -188,10 +188,10 @@ export class SpaceService {
|
|||||||
|
|
||||||
async getSpacesHierarchyForCommunity(
|
async getSpacesHierarchyForCommunity(
|
||||||
params: CommunitySpaceParam,
|
params: CommunitySpaceParam,
|
||||||
getSpaceDto?: GetSpaceDto,
|
getSpaceDto?: GetSpaceDto & { search?: string },
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { communityUuid, projectUuid } = params;
|
const { communityUuid, projectUuid } = params;
|
||||||
const { onlyWithDevices } = getSpaceDto;
|
const { onlyWithDevices, search } = getSpaceDto;
|
||||||
await this.validationService.validateCommunityAndProject(
|
await this.validationService.validateCommunityAndProject(
|
||||||
communityUuid,
|
communityUuid,
|
||||||
projectUuid,
|
projectUuid,
|
||||||
@ -234,6 +234,13 @@ export class SpaceService {
|
|||||||
})
|
})
|
||||||
.andWhere('space.disabled = :disabled', { disabled: false });
|
.andWhere('space.disabled = :disabled', { disabled: false });
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
queryBuilder.andWhere(
|
||||||
|
'(space.spaceName ILIKE :search OR parent.spaceName ILIKE :search)',
|
||||||
|
{ search: `%${search}%` },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (onlyWithDevices) {
|
if (onlyWithDevices) {
|
||||||
queryBuilder.innerJoin('space.devices', 'devices');
|
queryBuilder.innerJoin('space.devices', 'devices');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user