From 2c90b4defce8c6c0c78af6c5547ab2861809ea5e Mon Sep 17 00:00:00 2001 From: Fachba Date: Thu, 30 Apr 2026 16:54:12 +0700 Subject: [PATCH] fix: update saveReminder method to handle reset logic for reminders --- services/notifikasi-wa.service.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/notifikasi-wa.service.js b/services/notifikasi-wa.service.js index b44ac30..f4cd541 100644 --- a/services/notifikasi-wa.service.js +++ b/services/notifikasi-wa.service.js @@ -31,7 +31,7 @@ const filePathLog = path.join(process.cwd(), 'scheduler', 'log.json'); class NotifikasiWaService { - async saveReminder(data) { + async saveReminder(data, isReset = false) { console.log(`Reminder proses dibuat`); try { @@ -64,7 +64,12 @@ class NotifikasiWaService { created_at: now.toISOString() // opsional (full timestamp) }; - existing.push(newData); + if (!isReset) { + existing.push(newData); + } else { + existing = newData; + } + await fs.writeFile(filePath, JSON.stringify(existing, null, 2), 'utf-8'); @@ -268,7 +273,7 @@ class NotifikasiWaService { return false; } - this.saveReminder(newData); + this.saveReminder(newData, true); await this.saveLogReminder({ message: `Reminder ${id} berhasil dihapus` @@ -344,7 +349,7 @@ class NotifikasiWaService { return true; }); - await this.saveReminder(data); + await this.saveReminder(data, true); }, 60 * 1000); }