Skip to content

Commit

Permalink
refactor: Update PlanService to send plan alert for user
Browse files Browse the repository at this point in the history
  • Loading branch information
suk-6 committed Jul 19, 2024
1 parent bd04251 commit a790384
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/modules/plan/plan.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan, PlanStatus, User } from '@prisma/client';
import { PlanStatus, User } from '@prisma/client';
import { DateTime } from 'luxon';

import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
Expand Down Expand Up @@ -255,7 +255,9 @@ export class PlanService {
return Math.abs(DateTime.fromISO(date).diffNow('minutes').minutes) <= 30;
}

async sendAlarmManual(user: User, plan: Plan, targetUserId: string) {
async sendAlarmManual(user: User, targetUserId: string) {
const plan = await this.getPlan(user);

const targetUser = await this.prisma.user.findUnique({
where: {
id: targetUserId,
Expand All @@ -265,8 +267,7 @@ export class PlanService {
if (targetUser.planId !== plan.id)
throw new HttpException('User is not in the same plan', HttpStatus.BAD_GATEWAY);

if (!this.isAlarmAvailable(plan.date))
throw new HttpException('Plan is not in 30 minutes', HttpStatus.BAD_REQUEST);
if (!plan.isAlarmAvailable) throw new HttpException('Plan is not in 30 minutes', HttpStatus.BAD_REQUEST);

const targetUserFCMToken = targetUser.FCMToken;
if (!targetUserFCMToken)
Expand Down

0 comments on commit a790384

Please sign in to comment.