wisdom #62
@@ -1 +0,0 @@
|
|||||||
[]
|
|
||||||
@@ -597,7 +597,7 @@ class NotifikasiWaService {
|
|||||||
limit: 100,
|
limit: 100,
|
||||||
page: 1,
|
page: 1,
|
||||||
criteria: "",
|
criteria: "",
|
||||||
active: 1,
|
active: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const allDeviceReminders = await getDeviceReminderMonthlyDb(deviceId);
|
const allDeviceReminders = await getDeviceReminderMonthlyDb(deviceId);
|
||||||
@@ -621,7 +621,6 @@ class NotifikasiWaService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const nowKey = now.format('MM-DD HH:mm');
|
const nowKey = now.format('MM-DD HH:mm');
|
||||||
|
|
||||||
const reminderKey = reminderAt.format('MM-DD HH:mm');
|
const reminderKey = reminderAt.format('MM-DD HH:mm');
|
||||||
|
|
||||||
const isTriggered = nowKey >= reminderKey;
|
const isTriggered = nowKey >= reminderKey;
|
||||||
@@ -634,7 +633,9 @@ class NotifikasiWaService {
|
|||||||
currentMonth
|
currentMonth
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!checkNotifExist) {
|
if (checkNotifExist) {
|
||||||
|
throw new Error(`Reminder untuk device ${deviceName} bulan ${currentMonth} sudah pernah dibuat.`);
|
||||||
|
}
|
||||||
|
|
||||||
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
||||||
|
|
||||||
@@ -655,17 +656,14 @@ class NotifikasiWaService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const resultNotificationError = await InsertNotificationErrorDb(data);
|
const resultNotificationError = await InsertNotificationErrorDb(data);
|
||||||
|
|
||||||
const results = await getAllContactDb(paramDb);
|
const results = await getAllContactDb(paramDb);
|
||||||
|
|
||||||
const dataUsers = results.data;
|
const dataUsers = results.data;
|
||||||
|
|
||||||
let isSendNotification = false;
|
let isSendNotification = false;
|
||||||
|
let successLogMessage = "";
|
||||||
|
|
||||||
for (const dataUser of dataUsers) {
|
for (const dataUser of dataUsers) {
|
||||||
if (dataUser.is_active || dataUser.is_active === 1) {
|
if (dataUser.is_active) {
|
||||||
|
|
||||||
return { success: false, message: 'Tidak ada data user yang aktif.' };
|
|
||||||
|
|
||||||
const tokenRedirect = await generateTokenRedirect(
|
const tokenRedirect = await generateTokenRedirect(
|
||||||
dataUser.contact_phone,
|
dataUser.contact_phone,
|
||||||
@@ -674,7 +672,6 @@ class NotifikasiWaService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const encodedToken = encodeURIComponent(tokenRedirect);
|
const encodedToken = encodeURIComponent(tokenRedirect);
|
||||||
|
|
||||||
const shortUrl = await shortUrltiny(encodedToken);
|
const shortUrl = await shortUrltiny(encodedToken);
|
||||||
|
|
||||||
const bodyMessage =
|
const bodyMessage =
|
||||||
@@ -690,10 +687,8 @@ class NotifikasiWaService {
|
|||||||
bodyMessage: bodyMessage,
|
bodyMessage: bodyMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
const resultNotificationErrorUser =
|
const resultNotificationErrorUser = await createNotificationErrorUserDb({
|
||||||
await createNotificationErrorUserDb({
|
|
||||||
notification_error_id: param.idData,
|
notification_error_id: param.idData,
|
||||||
|
|
||||||
contact_phone: param.userPhone,
|
contact_phone: param.userPhone,
|
||||||
contact_name: param.userName,
|
contact_name: param.userName,
|
||||||
message_error_issue: param.bodyMessage,
|
message_error_issue: param.bodyMessage,
|
||||||
@@ -705,11 +700,6 @@ 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,
|
||||||
{
|
{
|
||||||
@@ -717,6 +707,20 @@ class NotifikasiWaService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (resultSend.success) {
|
||||||
|
isSendNotification = resultSend.success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateNotificationErrorDb(
|
||||||
|
resultNotificationError.notification_error_id,
|
||||||
|
{
|
||||||
|
is_send: isSendNotification,
|
||||||
|
is_delivered: isSendNotification,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
await this.saveReminder({
|
await this.saveReminder({
|
||||||
notification_log: resultNotificationError.notification_error_id,
|
notification_log: resultNotificationError.notification_error_id,
|
||||||
error_code_id: data['error_code_id'],
|
error_code_id: data['error_code_id'],
|
||||||
@@ -730,26 +734,14 @@ class NotifikasiWaService {
|
|||||||
last_run_indo: now.format('DD-MM-YYYY HH:mm:ss'),
|
last_run_indo: now.format('DD-MM-YYYY HH:mm:ss'),
|
||||||
next_run: null,
|
next_run: null,
|
||||||
next_run_indo: null,
|
next_run_indo: null,
|
||||||
message: `Reminder untuk ${deviceName} dengan reminder bulan ${currentMonth} telah dijalankan pada ${now.format('DD-MM-YYYY HH:mm:ss')}, hasil pengiriman: ${resultSend.success ? 'sukses' : 'gagal'}`,
|
message: `Reminder untuk ${deviceName} bulan ${currentMonth} telah dijalankan. Detail: ${successLogMessage}`,
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
if (resultSend.success) {
|
|
||||||
isSendNotification = resultSend.success;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateNotificationErrorDb(
|
return { success: true, message: "Reminder has been sent." };
|
||||||
resultNotificationError.notification_error_id,
|
|
||||||
{
|
|
||||||
is_send: isSendNotification,
|
|
||||||
is_delivered: isSendNotification,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error onNotificationReminder:', err);
|
console.log('Error onNotificationReminder:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user