add: reminder whatsapp sparepart monthly

This commit is contained in:
Muhammad Afif
2026-06-05 09:17:45 +07:00
parent 3d53bf4702
commit 40de826da9
6 changed files with 249 additions and 13 deletions

View File

@@ -31,7 +31,7 @@ const {
} = require("../db/notification_wa.db");
const { ErrorHandler } = require("../helpers/error");
const { getSparepartsByYearlyDb } = require("../db/sparepart.db");
const { getSparepartsByYearlyDb, getSparepartsByMonthlyDb } = require("../db/sparepart.db");
const notifikasiWaService = require("./notifikasi-wa.service");
@@ -140,11 +140,18 @@ class NotificationService {
notification.is_reminder = false;
notification.spareparts_reminder = [];
if (notification.message_error_issue) {
const sparepartsReminder = await getSparepartsByYearlyDb(notification.error_code_id);
notification.spareparts_reminder = sparepartsReminder ?? [];
const [sparepartsYearly, sparepartsMonthly] = await Promise.all([
getSparepartsByYearlyDb(notification.error_code_id),
getSparepartsByMonthlyDb(notification.error_code_id)
]);
notification.spareparts_reminder = [
...(sparepartsYearly ?? []),
...(sparepartsMonthly ?? [])
];
notification.is_reminder = true;
}
return notification;
@@ -172,7 +179,7 @@ class NotificationService {
if (!notification.is_read) {
const updateStatus = await updateNotificationErrorDb(
notification_error_id,
{ is_read: true}
{ is_read: true }
);
if (!updateStatus) {