Merge branch 'wisdom'
# Conflicts: # services/notification_error.service.js
This commit is contained in:
@@ -297,7 +297,7 @@ const mqttOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mqttUrl = 'ws://localhost:1884'; // Ganti dengan broker kamu
|
const mqttUrl = 'ws://localhost:1884'; // Ganti dengan broker kamu
|
||||||
const topic = 'morek';
|
const topic = process.env.TOPIC_COD ?? 'morek';
|
||||||
|
|
||||||
const mqttClient = mqtt.connect(mqttUrl, mqttOptions);
|
const mqttClient = mqtt.connect(mqttUrl, mqttOptions);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ router
|
|||||||
.get(verifyToken.verifyAccessToken, NotificationErrorController.getById)
|
.get(verifyToken.verifyAccessToken, NotificationErrorController.getById)
|
||||||
.put(
|
.put(
|
||||||
verifyToken.verifyAccessToken,
|
verifyToken.verifyAccessToken,
|
||||||
verifyAccess(),
|
// verifyAccess(),
|
||||||
NotificationErrorController.update
|
NotificationErrorController.update
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.route("/")
|
router.route("/")
|
||||||
.get(verifyToken.verifyAccessToken, NotificationErrorLogController.getAll)
|
.get(verifyToken.verifyAccessToken, NotificationErrorLogController.getAll)
|
||||||
.post(verifyToken.verifyAccessToken, verifyAccess(), NotificationErrorLogController.create);
|
.post(
|
||||||
|
verifyToken.verifyAccessToken,
|
||||||
|
// verifyAccess(),
|
||||||
|
NotificationErrorLogController.create);
|
||||||
|
|
||||||
router.route("/:id")
|
router.route("/:id")
|
||||||
.get(verifyToken.verifyAccessToken, NotificationErrorLogController.getById);
|
.get(verifyToken.verifyAccessToken, NotificationErrorLogController.getById);
|
||||||
|
|||||||
@@ -186,22 +186,25 @@ class NotificationService {
|
|||||||
if (activeUsers.length < 1)
|
if (activeUsers.length < 1)
|
||||||
throw new ErrorHandler(404, "No active contacts");
|
throw new ErrorHandler(404, "No active contacts");
|
||||||
|
|
||||||
this._executeResendWA(id, activeUsers, deviceNotification, errorCode).catch(
|
this._executeResendInBackground(
|
||||||
(err) => console.error("process error:", err)
|
id,
|
||||||
);
|
activeUsers,
|
||||||
|
deviceNotification,
|
||||||
|
errorCode
|
||||||
|
).catch((err) => console.error("Background Process Error:", err));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count: activeUsers.length,
|
count: activeUsers.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async _executeResendWA(
|
static async _executeResendInBackground(
|
||||||
id,
|
id,
|
||||||
activeUsers,
|
activeUsers,
|
||||||
deviceNotification,
|
deviceNotification,
|
||||||
errorCode
|
errorCode
|
||||||
) {
|
) {
|
||||||
console.log(`process id: ${id}`);
|
console.log(`process untuk ID: ${id}`);
|
||||||
|
|
||||||
const sendPromises = activeUsers.map(async (user) => {
|
const sendPromises = activeUsers.map(async (user) => {
|
||||||
try {
|
try {
|
||||||
@@ -232,10 +235,9 @@ class NotificationService {
|
|||||||
is_delivered: isSuccess,
|
is_delivered: isSuccess,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { phone: user.contact_phone, status: true };
|
return { phone: user.contact_phone, status: "success" };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(`Gagal mengirim ke ${user.contact_phone}:`, err.message);
|
||||||
console.log(`Gagal mengirim ke ${user.contact_phone}:`, err.message);
|
|
||||||
return {
|
return {
|
||||||
phone: user.contact_phone,
|
phone: user.contact_phone,
|
||||||
status: "failed",
|
status: "failed",
|
||||||
@@ -247,9 +249,9 @@ class NotificationService {
|
|||||||
const results = await Promise.all(sendPromises);
|
const results = await Promise.all(sendPromises);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Notification resend has been succesfully: ${
|
`Resend chat: ${
|
||||||
results.filter((r) => r.status === "success").length
|
results.filter((r) => r.status === "success").length
|
||||||
}, Error: ${results.filter((r) => r.status === "failed").length}`
|
}, Gagal: ${results.filter((r) => r.status === "failed").length}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class NotifikasiWaService {
|
|||||||
// "c_6501": 0
|
// "c_6501": 0
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (topic === "morek") {
|
if (topic === process.env.TOPIC_COD ?? "morek") {
|
||||||
const dataMqtt = JSON.parse(message);
|
const dataMqtt = JSON.parse(message);
|
||||||
|
|
||||||
const resultChanel = [];
|
const resultChanel = [];
|
||||||
@@ -78,11 +78,9 @@ class NotifikasiWaService {
|
|||||||
|
|
||||||
const bodyMessage =
|
const bodyMessage =
|
||||||
`Hai ${dataUser.contact_name || "-"}\n` +
|
`Hai ${dataUser.contact_name || "-"}\n` +
|
||||||
`Terjadi peringatan dengan kode error ${
|
`Terjadi peringatan dengan kode error ${errorCode?.error_code || "-"
|
||||||
errorCode?.error_code || "-"
|
|
||||||
} - ${errorCode?.error_code_name || "-"} ` +
|
} - ${errorCode?.error_code_name || "-"} ` +
|
||||||
`pada device ${
|
`pada device ${deviceNotification?.device_name || "-"
|
||||||
deviceNotification?.device_name || "-"
|
|
||||||
}, silahkan cek detail pada link berikut:\n` +
|
}, silahkan cek detail pada link berikut:\n` +
|
||||||
`${shortUrl}`;
|
`${shortUrl}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user