Skip to content

Commit

Permalink
refactor: Update PlanService to handle user not found in getPlan method
Browse files Browse the repository at this point in the history
  • Loading branch information
PleBea committed Jul 25, 2024
1 parent d2cb404 commit 55a2345
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/modules/plan/plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
},
Expand All @@ -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: '빨리 약속에 참석해주세요!',
Expand Down

0 comments on commit 55a2345

Please sign in to comment.