mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 10:59:39 +00:00
update community v2 search behavior
This commit is contained in:
@ -25,7 +25,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { SpaceService } from 'src/space/services';
|
||||
import { QueryRunner, SelectQueryBuilder } from 'typeorm';
|
||||
import { Brackets, QueryRunner, SelectQueryBuilder } from 'typeorm';
|
||||
import { AddCommunityDto, GetCommunityParams, ProjectParam } from '../dtos';
|
||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||
|
||||
@ -184,18 +184,44 @@ export class CommunityService {
|
||||
|
||||
let qb: undefined | SelectQueryBuilder<CommunityEntity> = undefined;
|
||||
|
||||
const matchingCommunityIdsQb = this.communityRepository
|
||||
.createQueryBuilder('c')
|
||||
.select('c.uuid')
|
||||
.leftJoin('c.spaces', 'space')
|
||||
.where('c.project = :projectUuid', { projectUuid })
|
||||
.andWhere('c.name != :orphanCommunityName', {
|
||||
orphanCommunityName: `${ORPHAN_COMMUNITY_NAME}-${project.name}`,
|
||||
})
|
||||
.distinct(true);
|
||||
|
||||
if (search) {
|
||||
matchingCommunityIdsQb
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where('c.name ILIKE :search');
|
||||
if (includeSpaces) qb.orWhere('space.spaceName ILIKE :search');
|
||||
}),
|
||||
)
|
||||
.setParameter('search', `%${search}%`);
|
||||
}
|
||||
|
||||
qb = this.communityRepository
|
||||
.createQueryBuilder('c')
|
||||
.where('c.project = :projectUuid', { projectUuid })
|
||||
.andWhere(`c.name != '${ORPHAN_COMMUNITY_NAME}-${project.name}'`)
|
||||
.distinct(true);
|
||||
|
||||
.andWhere('c.name != :orphanCommunityName', {
|
||||
orphanCommunityName: `${ORPHAN_COMMUNITY_NAME}-${project.name}`,
|
||||
})
|
||||
.andWhere(`c.uuid IN (${matchingCommunityIdsQb.getQuery()})`)
|
||||
.setParameters(matchingCommunityIdsQb.getParameters());
|
||||
if (includeSpaces) {
|
||||
qb.leftJoinAndSelect(
|
||||
'c.spaces',
|
||||
'space',
|
||||
'space.disabled = :disabled AND space.spaceName != :orphanSpaceName',
|
||||
{ disabled: false, orphanSpaceName: ORPHAN_SPACE_NAME },
|
||||
{
|
||||
disabled: false,
|
||||
orphanSpaceName: ORPHAN_SPACE_NAME,
|
||||
},
|
||||
)
|
||||
.leftJoinAndSelect('space.parent', 'parent')
|
||||
.leftJoinAndSelect(
|
||||
@ -204,16 +230,7 @@ export class CommunityService {
|
||||
'children.disabled = :disabled',
|
||||
{ disabled: false },
|
||||
);
|
||||
// .leftJoinAndSelect('space.spaceModel', 'spaceModel')
|
||||
}
|
||||
|
||||
if (search) {
|
||||
qb.andWhere(
|
||||
`c.name ILIKE :search ${includeSpaces ? 'OR space.space_name ILIKE :search' : ''}`,
|
||||
{ search: `%${search}%` },
|
||||
);
|
||||
}
|
||||
|
||||
const customModel = TypeORMCustomModel(this.communityRepository);
|
||||
|
||||
const { baseResponseDto, paginationResponseDto } =
|
||||
|
Reference in New Issue
Block a user