refactor: update notification service to use deleteReminder from notifikasiWaService and improve data filtering logic
This commit is contained in:
@@ -31,9 +31,10 @@ const {
|
||||
} = require("../db/notification_wa.db");
|
||||
|
||||
const { ErrorHandler } = require("../helpers/error");
|
||||
const { deleteReminder } = require("./notifikasi-wa.service");
|
||||
const { getSparepartsByYearlyDb } = require("../db/sparepart.db");
|
||||
|
||||
const notifikasiWaService = require("./notifikasi-wa.service");
|
||||
|
||||
class NotificationService {
|
||||
static async getAllNotification(param) {
|
||||
try {
|
||||
@@ -162,7 +163,7 @@ class NotificationService {
|
||||
|
||||
const notification = Array.isArray(dataExist) ? dataExist[0] : dataExist;
|
||||
|
||||
await deleteReminder(notification_error_id)
|
||||
await notifikasiWaService.deleteReminder(notification_error_id)
|
||||
|
||||
if (notification.is_read === true) {
|
||||
return { success: true, message: "Notification has already been read" };
|
||||
|
||||
@@ -258,9 +258,9 @@ class NotifikasiWaService {
|
||||
}
|
||||
|
||||
async deleteReminder(id) {
|
||||
let data = this.loadReminder();
|
||||
let data = await this.loadReminder();
|
||||
|
||||
const newData = data.filter(item => item.notification_log !== id);
|
||||
const newData = data?.filter(item => item.notification_log !== id);
|
||||
|
||||
// cek apakah ada yang terhapus
|
||||
if (data.length === newData.length) {
|
||||
@@ -283,7 +283,7 @@ class NotifikasiWaService {
|
||||
const now = new Date();
|
||||
let data = this.loadReminder();
|
||||
|
||||
data = data.filter(async (item) => {
|
||||
data = data?.filter(async (item) => {
|
||||
|
||||
// ❌ jika non aktif → hapus
|
||||
if (!item.active) return false;
|
||||
|
||||
Reference in New Issue
Block a user