Skip to content

Commit

Permalink
feat: 지난 reminder는 count에서 제외 - Quickchive#180
Browse files Browse the repository at this point in the history
알람을 보낼 때마다 해당 reminder를 지우려 했으나
null 할당에 실패해서
그냥 지난 reminder는 카운트에서 제외하는 걸로 추가 구현
  • Loading branch information
hou27 committed Mar 23, 2023
1 parent c46072c commit 8c717a7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,32 @@ export class ContentsService {

async loadReminderCount(user: User): Promise<LoadReminderCountOutput> {
try {
const reminderCount = await this.contents
const reminderCountThatIsNotNull = await this.contents
.createQueryBuilder('content')
.where('content.userId = :userId', { userId: user.id })
.andWhere('content.reminder IS NOT NULL')
.getCount();

// get reminder not null
const reminderContents = await this.contents
.createQueryBuilder('content')
.where('content.userId = :userId', { userId: user.id })
.andWhere('content.reminder IS NOT NULL')
.getOne();

// get reminder is past
const reminderDate = new Date();
const reminderCountThatIsPast = await this.contents
.createQueryBuilder('content')
.where('content.userId = :userId', { userId: user.id })
.andWhere('content.reminder IS NOT NULL')
.andWhere('content.reminder < :reminderDate', { reminderDate })
.getCount();

// minus reminderCountThatIsPast from reminderCount
const reminderCount =
reminderCountThatIsNotNull - reminderCountThatIsPast;

return {
count: reminderCount,
};
Expand Down

0 comments on commit 8c717a7

Please sign in to comment.