add: self-signed certificate
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ class NotifikasiWaService {
|
||||
|
||||
let bodyWithUrl = `${param.bodyMessage}\n🔗 ${shortUrl}`;
|
||||
|
||||
console.log(bodyWithUrl)
|
||||
|
||||
param.bodyMessage = bodyWithUrl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user