Merge branch 'wisdom'
# Conflicts: # services/notification_error.service.js
This commit is contained in:
@@ -186,22 +186,25 @@ class NotificationService {
|
||||
if (activeUsers.length < 1)
|
||||
throw new ErrorHandler(404, "No active contacts");
|
||||
|
||||
this._executeResendWA(id, activeUsers, deviceNotification, errorCode).catch(
|
||||
(err) => console.error("process error:", err)
|
||||
);
|
||||
this._executeResendInBackground(
|
||||
id,
|
||||
activeUsers,
|
||||
deviceNotification,
|
||||
errorCode
|
||||
).catch((err) => console.error("Background Process Error:", err));
|
||||
|
||||
return {
|
||||
count: activeUsers.length,
|
||||
};
|
||||
}
|
||||
|
||||
static async _executeResendWA(
|
||||
static async _executeResendInBackground(
|
||||
id,
|
||||
activeUsers,
|
||||
deviceNotification,
|
||||
errorCode
|
||||
) {
|
||||
console.log(`process id: ${id}`);
|
||||
console.log(`process untuk ID: ${id}`);
|
||||
|
||||
const sendPromises = activeUsers.map(async (user) => {
|
||||
try {
|
||||
@@ -232,10 +235,9 @@ class NotificationService {
|
||||
is_delivered: isSuccess,
|
||||
});
|
||||
|
||||
return { phone: user.contact_phone, status: true };
|
||||
return { phone: user.contact_phone, status: "success" };
|
||||
} catch (err) {
|
||||
|
||||
console.log(`Gagal mengirim ke ${user.contact_phone}:`, err.message);
|
||||
console.error(`Gagal mengirim ke ${user.contact_phone}:`, err.message);
|
||||
return {
|
||||
phone: user.contact_phone,
|
||||
status: "failed",
|
||||
@@ -247,9 +249,9 @@ class NotificationService {
|
||||
const results = await Promise.all(sendPromises);
|
||||
|
||||
console.log(
|
||||
`Notification resend has been succesfully: ${
|
||||
`Resend chat: ${
|
||||
results.filter((r) => r.status === "success").length
|
||||
}, Error: ${results.filter((r) => r.status === "failed").length}`
|
||||
}, Gagal: ${results.filter((r) => r.status === "failed").length}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user