feat: enhance notification and reminder services with logging and time tracking
This commit is contained in:
@@ -31,6 +31,7 @@ const {
|
|||||||
} = require("../db/notification_wa.db");
|
} = require("../db/notification_wa.db");
|
||||||
|
|
||||||
const { ErrorHandler } = require("../helpers/error");
|
const { ErrorHandler } = require("../helpers/error");
|
||||||
|
const { deleteReminder } = require("./notifikasi-wa.service");
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
static async getAllNotification(param) {
|
static async getAllNotification(param) {
|
||||||
@@ -150,6 +151,8 @@ class NotificationService {
|
|||||||
|
|
||||||
const notification = Array.isArray(dataExist) ? dataExist[0] : dataExist;
|
const notification = Array.isArray(dataExist) ? dataExist[0] : dataExist;
|
||||||
|
|
||||||
|
await deleteReminder(notification_error_id)
|
||||||
|
|
||||||
if (notification.is_read === true) {
|
if (notification.is_read === true) {
|
||||||
return { success: true, message: "Notification has already been read" };
|
return { success: true, message: "Notification has already been read" };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,28 @@ class NotifikasiWaService {
|
|||||||
existing = [];
|
existing = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
existing.push(data);
|
// 👉 selalu tambahkan waktu saat insert
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const newData = {
|
||||||
|
...data,
|
||||||
|
time: now.toLocaleTimeString('id-ID', {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}),
|
||||||
|
created_at: now.toISOString() // opsional (full timestamp)
|
||||||
|
};
|
||||||
|
|
||||||
|
existing.push(newData);
|
||||||
|
|
||||||
await fs.writeFile(filePath, JSON.stringify(existing, null, 2), 'utf-8');
|
await fs.writeFile(filePath, JSON.stringify(existing, null, 2), 'utf-8');
|
||||||
|
|
||||||
|
await this.saveLogReminder({
|
||||||
|
message: `Reminder berhasil disimpan`,
|
||||||
|
data
|
||||||
|
})
|
||||||
|
|
||||||
console.log(`Reminder berhasil disimpan`);
|
console.log(`Reminder berhasil disimpan`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error saveReminder:', error);
|
console.log('Error saveReminder:', error);
|
||||||
@@ -81,7 +99,20 @@ class NotifikasiWaService {
|
|||||||
existing = [];
|
existing = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
existing.push(data);
|
// 👉 selalu tambahkan waktu saat insert
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const newData = {
|
||||||
|
...data,
|
||||||
|
time: now.toLocaleTimeString('id-ID', {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}),
|
||||||
|
created_at: now.toISOString() // opsional (full timestamp)
|
||||||
|
};
|
||||||
|
|
||||||
|
existing.push(newData);
|
||||||
|
|
||||||
await fs.writeFile(filePathLog, JSON.stringify(existing, null, 2), 'utf-8');
|
await fs.writeFile(filePathLog, JSON.stringify(existing, null, 2), 'utf-8');
|
||||||
|
|
||||||
@@ -235,6 +266,10 @@ class NotifikasiWaService {
|
|||||||
|
|
||||||
this.saveReminder(newData);
|
this.saveReminder(newData);
|
||||||
|
|
||||||
|
await this.saveLogReminder({
|
||||||
|
message: `Reminder ${id} berhasil dihapus`
|
||||||
|
})
|
||||||
|
|
||||||
console.log(`Reminder ${id} berhasil dihapus`);
|
console.log(`Reminder ${id} berhasil dihapus`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -471,6 +506,11 @@ class NotifikasiWaService {
|
|||||||
param.bodyMessage
|
param.bodyMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.saveLogReminder({
|
||||||
|
message: `Reminder dijalankan`,
|
||||||
|
resultSend
|
||||||
|
})
|
||||||
|
|
||||||
await updateNotificationErrorUserDb(
|
await updateNotificationErrorUserDb(
|
||||||
resultNotificationErrorUser[0].notification_error_user_id,
|
resultNotificationErrorUser[0].notification_error_user_id,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user