diff --git a/controllers/notification_error_user.controller.js b/controllers/notification_error_user.controller.js index bed4cb7..ef68653 100644 --- a/controllers/notification_error_user.controller.js +++ b/controllers/notification_error_user.controller.js @@ -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, diff --git a/routes/notification_error_user.route.js b/routes/notification_error_user.route.js index b68aacc..61a5f0c 100644 --- a/routes/notification_error_user.route.js +++ b/routes/notification_error_user.route.js @@ -29,7 +29,7 @@ router ); router.post( - "/resend/:id", + "/resend/:id/:contact_phone", verifyToken.verifyAccessToken, verifyAccess(), NotificationErrorUserController.resend diff --git a/services/notification_error_user.service.js b/services/notification_error_user.service.js index de2ef7c..3673210 100644 --- a/services/notification_error_user.service.js +++ b/services/notification_error_user.service.js @@ -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.` ); }