Merge pull request 'add: self-signed certificate' (#25) from wisdom into main

Reviewed-on: #25
This commit is contained in:
2026-01-06 05:38:46 +00:00
4 changed files with 87 additions and 75 deletions

View File

@@ -1,5 +1,10 @@
const { default: axios } = require('axios');
const CryptoJS = require('crypto-js');
const https = require('https');
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
const generateTokenRedirect = async (userPhone, userName, id) => {
@@ -18,7 +23,7 @@ const shortUrltiny = async (encodedToken) => {
const encodedUrl = encodeURIComponent(url); // ⬅️ Encode dulu!
const response = await axios.get(`https://tinyurl.com/api-create.php?url=${encodedUrl}`);
const response = await axios.get(`https://tinyurl.com/api-create.php?url=${encodedUrl}`,{ httpsAgent });
let shortUrl = response.data;
if (!shortUrl.startsWith('http')) {
@@ -38,11 +43,11 @@ const sendNotifikasi = async (phone, message) => {
const endPointWhatsapp = process.env.ENDPOINT_WHATSAPP;
const response = await axios.post(endPointWhatsapp, payload);
const response = await axios.post(endPointWhatsapp, payload, { httpsAgent });
// console.log('response', response);
try {
const response = await axios.post(endPointWhatsapp, payload);
const response = await axios.post(endPointWhatsapp, payload, { httpsAgent });
// console.log(response.data);
return response?.data
} catch (error) {

View File

@@ -64,7 +64,7 @@ class NotificationService {
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
return error
}
}
@@ -171,76 +171,84 @@ class NotificationService {
}
static async resendNotification(id) {
try {
const deviceNotification = await getNotificationByIdDb(id);
if (!deviceNotification) {
throw new ErrorHandler(404, "Notification Data not found");
try {
const deviceNotification = await getNotificationByIdDb(id);
if (!deviceNotification) {
throw new ErrorHandler(404, "Notification Data not found");
}
const errorCodeId = deviceNotification.error_code_id;
const errorCode = await getErrorCodeByIdDb(errorCodeId);
const dataExist = await getUsersNotificationErrorDb(id);
const activeUsers =
dataExist?.filter((user) => user.is_active === true) || [];
if (activeUsers.length < 1) {
throw new ErrorHandler(
404,
"No active contacts found for this notification"
);
}
const results = await Promise.all(
activeUsers.map(async (user) => {
try {
const tokenRedirect = await generateTokenRedirect(
user.contact_phone,
user.contact_name,
user.notification_error_id
);
const encodedToken = encodeURIComponent(tokenRedirect);
const shortUrl = await shortUrltiny(encodedToken);
const bodyWithUrl =
`Hai ${user.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` +
`${shortUrl}`;
const resultSend = await sendNotifikasi(
user.contact_phone,
bodyWithUrl
);
const isSuccess = !resultSend?.error;
await updateNotificationErrorDb(user.notification_error_id, {
is_send: isSuccess,
is_delivered: isSuccess,
});
return {
contact_name: user.contact_name,
contact_phone: user.contact_phone,
is_send: isSuccess,
is_delivered: isSuccess,
};
} catch (err) {
return err;
}
})
);
return {
notification_error_id: id,
device_name: deviceNotification.device_name,
error_code: errorCode.error_code,
error_code_name: errorCode.error_code_name,
users: results,
message: "Berhasil mengirim ulang notifikasi",
};
} catch (err) {
return err;
}
const errorCodeId = deviceNotification.error_code_id;
const errorCode = await getErrorCodeByIdDb(errorCodeId);
const dataExist = await getUsersNotificationErrorDb(id);
const activeUsers = dataExist?.filter((user) => user.is_active === true) || [];
if (activeUsers.length < 1) {
throw new ErrorHandler(404, "No active contacts found for this notification");
}
const results = await Promise.all(
activeUsers.map(async (user) => {
try {
const tokenRedirect = await generateTokenRedirect(
user.contact_phone,
user.contact_name,
user.notification_error_id
);
const encodedToken = encodeURIComponent(tokenRedirect);
const shortUrl = await shortUrltiny(encodedToken);
const bodyWithUrl = `Hai ${user.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` +
`${shortUrl}`;
const resultSend = await sendNotifikasi(user.contact_phone, bodyWithUrl);
const isSuccess = !resultSend?.error;
await updateNotificationErrorDb(user.notification_error_id, {
is_send: isSuccess,
is_delivered: isSuccess,
});
return {
contact_name: user.contact_name,
contact_phone: user.contact_phone,
is_send: isSuccess,
is_delivered: isSuccess,
};
} catch (err) {
return {
contact_name: user.contact_name,
error: err.message,
is_send: false
};
}
})
);
return {
notification_error_id: id,
device_name: deviceNotification.device_name,
error_code: errorCode.error_code,
error_code_name:errorCode.error_code_name,
users: results,
message: "Berhasil mengirim ulang notifikasi",
};
} catch (error) {
throw new ErrorHandler(error.statusCode || 500, error.message);
}
}
}
module.exports = NotificationService;

View File

@@ -163,8 +163,8 @@ class NotificationErrorUserService {
error_code_name: data.error_code_name,
message: "Berhasil mengirim ulang notifikasi",
};
} catch (error) {
throw new ErrorHandler(error.statusCode || 500, error.message);
} catch (err) {
return err
}
}
}

View File

@@ -75,7 +75,6 @@ class NotifikasiWaService {
let bodyWithUrl = `${param.bodyMessage}\n🔗 ${shortUrl}`;
console.log(bodyWithUrl)
param.bodyMessage = bodyWithUrl