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