wisdom #62
@@ -255,23 +255,20 @@ const getReminderNotificationErrorByYearlyDb = async (errorCode, chanel, year) =
|
|||||||
return result.recordset[0];
|
return result.recordset[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getReminderNotificationErrorByMonthlyDb = async (errorCode, monthly) => {
|
const getReminderNotificationErrorByMonthlyDb = async (errorCode, monthly, deviceId) => {
|
||||||
const queryText = `
|
const queryText = `
|
||||||
SELECT a.*
|
SELECT a.*
|
||||||
|
|
||||||
FROM notification_error a
|
FROM notification_error a
|
||||||
|
|
||||||
WHERE a.error_code_id = $1
|
WHERE a.error_code_id = $1
|
||||||
AND MONTH(a.created_at) = $2
|
AND MONTH(a.created_at) = $2
|
||||||
AND a.message_error_issue LIKE 'reminder%'
|
AND a.message_error_issue LIKE '%device_id: ' + CAST($3 AS VARCHAR) + '%'
|
||||||
AND a.is_active = 1
|
AND a.is_active = 1
|
||||||
AND a.deleted_at IS NULL
|
AND a.deleted_at IS NULL
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await pool.query(queryText, [errorCode, monthly]);
|
const result = await pool.query(queryText, [errorCode, monthly, deviceId]);
|
||||||
return result.recordset[0];
|
return result.recordset[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getNotificationByIdDb,
|
getNotificationByIdDb,
|
||||||
getDeviceNotificationByIdDb,
|
getDeviceNotificationByIdDb,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
@@ -490,15 +490,13 @@ 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;
|
||||||
|
|
||||||
for (const dataUser of dataUsers) {
|
for (const dataUser of dataUsers) {
|
||||||
if (dataUser.is_active || dataUser.is_active === 1) {
|
if (dataUser.is_active) {
|
||||||
|
|
||||||
const tokenRedirect = await generateTokenRedirect(
|
const tokenRedirect = await generateTokenRedirect(
|
||||||
dataUser.contact_phone,
|
dataUser.contact_phone,
|
||||||
@@ -523,15 +521,13 @@ 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_name: param.userName,
|
||||||
contact_phone: param.userPhone,
|
message_error_issue: param.bodyMessage,
|
||||||
contact_name: param.userName,
|
is_send: false,
|
||||||
message_error_issue: param.bodyMessage,
|
});
|
||||||
is_send: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const resultSend = await sendNotifikasi(
|
const resultSend = await sendNotifikasi(
|
||||||
param.userPhone,
|
param.userPhone,
|
||||||
@@ -563,7 +559,7 @@ 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 ${chanel.value} telah dijalankan pada ${now.format('DD-MM-YYYY HH:mm:ss')}, hasil pengiriman: ${resultSend.success ? 'sukses' : 'gagal'}`,
|
message: `Reminder untuk ${deviceName} dengan reminder ${chanel.value} telah dijalankan pada ${now.format('DD-MM-YYYY HH:mm:ss')}}`,
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
if (resultSend.success) {
|
if (resultSend.success) {
|
||||||
@@ -599,7 +595,7 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
criteria: "",
|
criteria: "",
|
||||||
active: true,
|
active: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const allDeviceReminders = await getDeviceReminderMonthlyDb(deviceId);
|
const allDeviceReminders = await getDeviceReminderMonthlyDb(deviceId);
|
||||||
|
|
||||||
if (!allDeviceReminders || allDeviceReminders.length === 0) {
|
if (!allDeviceReminders || allDeviceReminders.length === 0) {
|
||||||
@@ -614,6 +610,7 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
|
|
||||||
if (deviceReminder?.reminder_at_monthly) {
|
if (deviceReminder?.reminder_at_monthly) {
|
||||||
const deviceName = deviceReminder.device_name ?? '-';
|
const deviceName = deviceReminder.device_name ?? '-';
|
||||||
|
const currentDeviceId = deviceReminder.device_id;
|
||||||
|
|
||||||
const reminderAt = dayjs.tz(
|
const reminderAt = dayjs.tz(
|
||||||
deviceReminder.reminder_at_monthly,
|
deviceReminder.reminder_at_monthly,
|
||||||
@@ -630,11 +627,13 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
|
|
||||||
const checkNotifExist = await getReminderNotificationErrorByMonthlyDb(
|
const checkNotifExist = await getReminderNotificationErrorByMonthlyDb(
|
||||||
monthlyCode,
|
monthlyCode,
|
||||||
currentMonth
|
currentMonth,
|
||||||
|
currentDeviceId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (checkNotifExist) {
|
if (checkNotifExist) {
|
||||||
throw new Error(`Reminder untuk device ${deviceName} bulan ${currentMonth} sudah pernah dibuat.`);
|
throw new Error(`Reminder untuk device ${deviceName} device id ${currentDeviceId} bulan ${currentMonth} sudah pernah dibuat.`);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
const spareparts = await getSparepartsByMonthlyDb(currentMonth);
|
||||||
@@ -652,7 +651,7 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
is_delivered: 0,
|
is_delivered: 0,
|
||||||
is_read: 0,
|
is_read: 0,
|
||||||
is_active: 1,
|
is_active: 1,
|
||||||
message_error_issue: `reminder device ${deviceName} in month ${currentMonth}`,
|
message_error_issue: `reminder device ${deviceName} device_id: ${currentDeviceId} in month ${currentMonth}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const resultNotificationError = await InsertNotificationErrorDb(data);
|
const resultNotificationError = await InsertNotificationErrorDb(data);
|
||||||
@@ -660,7 +659,6 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
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) {
|
if (dataUser.is_active) {
|
||||||
@@ -734,7 +732,7 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
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} bulan ${currentMonth} telah dijalankan. Detail: ${successLogMessage}`,
|
message: `Reminder untuk ${deviceName} bulan ${currentMonth} telah dijalankan.`,
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -749,7 +747,6 @@ async onMonthlySparepartReminder(deviceId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async restartWhatsapp() {
|
async restartWhatsapp() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user