mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
fix: add space condition to the join operator instead of general query (#423)
This commit is contained in:
@ -190,25 +190,26 @@ export class CommunityService {
|
||||
.distinct(true);
|
||||
|
||||
if (includeSpaces) {
|
||||
qb.leftJoinAndSelect('c.spaces', 'space', 'space.disabled = false')
|
||||
qb.leftJoinAndSelect(
|
||||
'c.spaces',
|
||||
'space',
|
||||
'space.disabled = :disabled AND space.spaceName != :orphanSpaceName',
|
||||
{ disabled: false, orphanSpaceName: ORPHAN_SPACE_NAME },
|
||||
)
|
||||
.leftJoinAndSelect('space.parent', 'parent')
|
||||
.leftJoinAndSelect(
|
||||
'space.children',
|
||||
'children',
|
||||
'children.disabled = :disabled',
|
||||
{ disabled: false },
|
||||
)
|
||||
// .leftJoinAndSelect('space.spaceModel', 'spaceModel')
|
||||
.andWhere('space.spaceName != :orphanSpaceName', {
|
||||
orphanSpaceName: ORPHAN_SPACE_NAME,
|
||||
})
|
||||
.andWhere('space.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}%` },
|
||||
{ search },
|
||||
);
|
||||
}
|
||||
|
||||
@ -216,7 +217,6 @@ export class CommunityService {
|
||||
|
||||
const { baseResponseDto, paginationResponseDto } =
|
||||
await customModel.findAll({ ...pageable, modelName: 'community' }, qb);
|
||||
|
||||
if (includeSpaces) {
|
||||
baseResponseDto.data = baseResponseDto.data.map((community) => ({
|
||||
...community,
|
||||
|
Reference in New Issue
Block a user