From 55a2345f7f6c5d842e0931129f3a43f9ccc5adac Mon Sep 17 00:00:00 2001 From: PleBea Date: Fri, 26 Jul 2024 01:49:48 +0900 Subject: [PATCH] refactor: Update PlanService to handle user not found in getPlan method --- src/modules/plan/plan.service.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/plan/plan.service.ts b/src/modules/plan/plan.service.ts index 7350ad6..2974c8c 100644 --- a/src/modules/plan/plan.service.ts +++ b/src/modules/plan/plan.service.ts @@ -255,11 +255,11 @@ export class PlanService { }); } - async isExpired(date: string) { + isExpired(date: string) { return DateTime.fromISO(date).diffNow('minutes').minutes < -30; } - async isAlarmAvailable(date: string) { + isAlarmAvailable(date: string) { return Math.abs(DateTime.fromISO(date).diffNow('minutes').minutes) <= 30; } @@ -294,9 +294,6 @@ export class PlanService { @Cron(CronExpression.EVERY_MINUTE) async sendAlarmAuto() { const plans = await this.prisma.plan.findMany({ - where: { - status: PlanStatus.WAITING, - }, include: { users: true, }, @@ -305,6 +302,8 @@ export class PlanService { for (const plan of plans) { if (this.isAlarmAvailable(plan.date)) { for (const user of plan.users) { + if (plan.status === PlanStatus.ALARMED) continue; + const fcmRes = this.firebase.sendNotificationByToken({ title: '약속 시간이 얼마 남지 않았어요!', body: '빨리 약속에 참석해주세요!',