From fddd06e06d2242b22088cf1c359c6299fc179770 Mon Sep 17 00:00:00 2001 From: ZaydSkaff Date: Mon, 23 Jun 2025 12:44:19 +0300 Subject: [PATCH] fix: add space condition to the join operator instead of general query (#423) --- src/community/services/community.service.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/community/services/community.service.ts b/src/community/services/community.service.ts index 3b213f9..d4ff99c 100644 --- a/src/community/services/community.service.ts +++ b/src/community/services/community.service.ts @@ -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,