v3

하… 이 이슈… 애초에 휴먼 에러 때문이었음;;

  1. andWhere 써야 하는데 where 사용

    1. where가 2개 들어가게 되면, 가장 마지막 where문을 제외하곤 이전 모든 where문은 무효화된다.
    const qb = this.postingsRepository
      .createQueryBuilder('p')
      .where('p.title LIKE :keyword', { keyword: `%${keyword}%` })
    
    if (budget) {
      // 휴먼 에러...
      qb.where('p.budget = :budget', { budget });
    
      // 이렇게 수정해야 함
      qb.andWhere('p.budget = :budget', { budget });
    }
    
  2. 다중 선택 가능 태그, andWhere 넣을 때 괄호( ) 생략

    if (themes) {
          const orCondtions = themes
            .map((theme, index) => `JSON_CONTAINS(p.theme, :theme${index})`)
            .join(' OR ');
          const params = themes.reduce(
            (params, theme, index) => ({
              ...params,
              [`theme${index}`]: JSON.stringify(theme),
            }),
            {}
          );
    
          // 여기가 문제!
          qb.andWhere(orCondtions, params);
    
          // orConditions 앞뒤로 괄호 붙이도록 수정
          qb.andWhere(`(${orCondtions})`, params);
        }
    

v2

NestJS에서 TypeORM의 Brackets를 사용해보자!

v1

이슈


코드