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 queryText = `
SELECT
brand_id,
device_code,
device_name,
device_location,

View File

@@ -46,13 +46,22 @@ const sendNotifikasi = async (phone, message) => {
try {
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) {
// console.error(error.response?.data || error.message);
return error.response?.data || error.message
return {
success: false,
statusCode: error.response?.status || null,
errorCode: error.code || null, // ECONNABORTED, dll
message: error.response?.data || error.message
};
}
};
module.exports = {

View File

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

View File

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

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,
}
);
}