eletrotupi / tcc/ api/src/lib/queue/processors/medicineReminders.tsdafa6f8a8e3b0e51605fc953a979d50ff6085b26
924 B | 28 lines Raw
1
import { Job } from "bullmq";
2
import { NotificationKind } from "@prisma/client";
3

4
import { createNotification } from "@app/services/notification.service";
5
import { MedicineReminderPayload } from "@app/lib/queue/types";
6
import { appTimeToday } from "@app/lib/appTime";
7
import { logger } from "@app/lib/logger";
8

9
export async function medicineReminderProcessor(job: Job): Promise<void> {
10
  const { userId, regimenId, medicineName, dosage, scheduledTime } =
11
    job.data as MedicineReminderPayload;
12

13
  logger.info(
14
    { jobId: job.id, userId, regimenId, medicine: medicineName },
15
    "[medicine-reminder] job started",
16
  );
17

18
  await createNotification({
19
    userId,
20
    kind: NotificationKind.MEDICINE_REMINDER,
21
    title: `Hora de tomar ${medicineName}`,
22
    body: dosage,
23
    scheduledFor: appTimeToday(scheduledTime),
24
    regimenId,
25
  });
26

27
  logger.info({ userId, regimenId }, "[medicine-reminder] notification stored");
28
}