fixing notification wa

This commit is contained in:
2026-01-12 13:11:45 +07:00
parent 47c99c878a
commit 31dbaaaadf
5 changed files with 28 additions and 20 deletions

View File

@@ -9,7 +9,7 @@ const {
shortUrltiny,
sendNotifikasi,
} = require("../db/notification_wa.db");
const { getErrorCodeByIdDb } = require("../db/brand_code.db");
const { getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
const { getDeviceNotificationByIdDb } = require("../db/notification_error.db");
class NotifikasiWaService {
@@ -48,11 +48,12 @@ class NotifikasiWaService {
const dataUsers = results.data;
for (const chanel of resultChanel) {
const errorCode = await getErrorCodeByIdDb(chanel.value);
const deviceNotification = await getDeviceNotificationByIdDb(
chanel.chanel_id
Number(chanel.chanel_id)
);
const errorCode = await getErrorCodeByBrandAndCodeDb(deviceNotification?.brand_id ?? 0, chanel.value);
const data = {
error_code_id: chanel.value,
error_chanel: chanel.chanel_id,
@@ -78,10 +79,9 @@ class NotifikasiWaService {
const bodyMessage =
`Hai ${dataUser.contact_name || "-"}\n` +
`Terjadi peringatan dengan kode error ${errorCode?.error_code || "-"
} - ${errorCode?.error_code_name || "-"} ` +
`pada device ${deviceNotification?.device_name || "-"
}, silahkan cek detail pada link berikut:\n` +
`Terjadi kode error ${chanel?.value ?? "-"} ${errorCode?.error_code_name ?? ""} Chanel ${chanel?.chanel_id ?? "-"} ` +
`pada device ${deviceNotification?.device_name ?? "berikut"
}, Silahkan cek detail pada link berikut:\n` +
`${shortUrl}`;
const param = {
@@ -93,10 +93,10 @@ class NotifikasiWaService {
const resultNotificationErrorUser =
await createNotificationErrorUserDb({
notification_error_id:
resultNotificationError.notification_error_id,
notification_error_id: param.idData,
contact_phone: param.userPhone,
contact_name: param.userName,
message_error_issue: param.bodyMessage,
is_send: false,
});
@@ -105,12 +105,10 @@ class NotifikasiWaService {
param.bodyMessage
);
console.log("resultSend: ", resultSend);
await updateNotificationErrorUserDb(
resultNotificationErrorUser[0].notification_error_user_id,
{
is_send: resultSend?.error ? false : true,
is_send: resultSend?.success ? true : false,
}
);
}