add: params contact_phone and validation resend chat wa in notif error user

This commit is contained in:
2026-01-01 18:31:09 +07:00
parent 889aa04808
commit bedc948a74
3 changed files with 19 additions and 12 deletions

View File

@@ -69,9 +69,9 @@ class NotificationErrorUserController {
static async resend(req, res) {
try {
const { id } = req.params;
const { id, contact_phone } = req.params;
const results = await NotificationErrorUserService.resendNotification(id);
const results = await NotificationErrorUserService.resendNotification(id, contact_phone);
const response = await setResponse(
results.data,

View File

@@ -29,7 +29,7 @@ router
);
router.post(
"/resend/:id",
"/resend/:id/:contact_phone",
verifyToken.verifyAccessToken,
verifyAccess(),
NotificationErrorUserController.resend

View File

@@ -34,7 +34,7 @@ class NotificationErrorUserService {
const result = await getNotificationErrorUserByIdDb(id);
if (result.length < 1)
throw new ErrorHandler(404, "NotificationErrorUser not found");
throw new ErrorHandler(404, "Notification Error User not found");
return result;
} catch (error) {
@@ -63,7 +63,7 @@ class NotificationErrorUserService {
const dataExist = await getNotificationErrorUserByIdDb(id);
if (dataExist.length < 1) {
throw new ErrorHandler(404, "NotificationErrorUser not found");
throw new ErrorHandler(404, "Notification Error User not found");
}
const result = await updateNotificationErrorUserDb(id, data);
@@ -80,7 +80,7 @@ class NotificationErrorUserService {
const dataExist = await getNotificationErrorUserByIdDb(id);
if (dataExist.length < 1) {
throw new ErrorHandler(404, "NotificationErrorUser not found");
throw new ErrorHandler(404, "Notification Error User not found");
}
const result = await deleteNotificationErrorUserDb(id, userId);
@@ -91,23 +91,30 @@ class NotificationErrorUserService {
}
}
static async resendNotification(id) {
static async resendNotification(id, contact_phone) {
try {
const dataExist = await getNotificationErrorUserByIdDb(id);
if (!dataExist || dataExist.length < 1) {
throw new ErrorHandler(
404,
"Data Notification Error User tidak ditemukan"
"Data Notification Error User not found"
);
}
const data = dataExist[0];
if (data.contact_is_active === 1) {
if (data.contact_phone !== contact_phone) {
throw new ErrorHandler(
404,
`Contact Phone with this phone ${contact_phone} not found.`
);
}
if (data.contact_is_active === false) {
throw new ErrorHandler(
400,
`Kontak dengan nomor ${
data.contact_phone || "terkait"
} tidak aktif.`
`Contact Phone with this phone ${data.contact_phone} not active.`
);
}