본문 바로가기
nest.js

[typeorm] countBy 사용시에 동일한 컬럼 두번 정의 불가

by Hwoarang757 2025. 3. 20.

TypeORM의 countBy()는 where 조건을 객체 형태로 받기 때문에, 같은 컬럼에 여러 개의 조건을 적용하려면 배열을 사용해야 한다고 하네요 ,,

배열 안에 동일한 컬럼명을 두번 명시 할 수가 없었습니다

MoreThanOrEqual ,LessThanOrEqual  대신 Between 으로 처리 해 보았습니다.

 

ex)

  async getUnReadCount(userToken : TokenPayload) : Promise<number> {

    this.logger.log(`${this.getUnReadCount.name} Occurred`);

    const startDt = `${CnvDateStrHelper.getDaySpanStr(-7)}000000`;
    const endDt = `${CnvDateStrHelper.getDaySpanStr(0)}235959`;

    this.logger.log(`${this.getUnReadCount.name} , startDt=${startDt} , endDt=${endDt}`);

    const val = await this.testRepository.countBy(
      {
       /* 
       regdt : MoreThanOrEqual(startDt) ,
       regdt : LessThanOrEqual(endDt) ,
       */
       regdt : Between(startDt , endDt), 
       readyn : 'Y' ,
       userid : userToken.userid
      },
    );

    return val;
  }