fixing notification wa #40

Merged
bragaz_rexita merged 1 commits from wisdom into main 2026-01-12 06:12:27 +00:00
5 changed files with 28 additions and 20 deletions

View File

@@ -46,6 +46,7 @@ const getNotificationByIdDb = async (id) => {
const getDeviceNotificationByIdDb = async (chanel_id) => { const getDeviceNotificationByIdDb = async (chanel_id) => {
const queryText = ` const queryText = `
SELECT SELECT
brand_id,
device_code, device_code,
device_name, device_name,
device_location, device_location,

View File

@@ -46,13 +46,22 @@ const sendNotifikasi = async (phone, message) => {
try { try {
const response = await axios.post(endPointWhatsapp, payload, { httpsAgent }); const response = await axios.post(endPointWhatsapp, payload, { httpsAgent });
// console.log(response.data);
return response?.data return {
success: true,
statusCode: response.status, // 200, 201, dll
data: response.data
};
} catch (error) { } catch (error) {
// console.error(error.response?.data || error.message); return {
return error.response?.data || error.message success: false,
statusCode: error.response?.status || null,
errorCode: error.code || null, // ECONNABORTED, dll
message: error.response?.data || error.message
};
} }
}; };
module.exports = { module.exports = {

View File

@@ -234,7 +234,7 @@ class NotificationService {
console.log("notifikasi wa:", resultSend) console.log("notifikasi wa:", resultSend)
const isSuccess = resultSend?.error ? false : true; const isSuccess = resultSend?.success ? true : false;
await updateNotificationErrorDb(user.notification_error_id, { await updateNotificationErrorDb(user.notification_error_id, {
is_send: isSuccess, is_send: isSuccess,

View File

@@ -152,7 +152,7 @@ class NotificationErrorUserService {
data.contact_phone, data.contact_phone,
bodyWithUrl bodyWithUrl
); );
const isSuccess = resultSend?.error ? false : true; const isSuccess = resultSend?.success ? true : false;
const updateData = { const updateData = {
is_send: isSuccess, is_send: isSuccess,

View File

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