add where for community name

This commit is contained in:
hannathkadher
2025-03-18 21:20:27 +04:00
parent ec851eda9d
commit 30badcde67
4 changed files with 27 additions and 5 deletions

View 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;
}

View File

@ -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;

View File

@ -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);
} }

View File

@ -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 } =