diff --git a/controllers/notification_error_log.controller.js b/controllers/notification_error_log.controller.js index 14c74e6..64b6670 100644 --- a/controllers/notification_error_log.controller.js +++ b/controllers/notification_error_log.controller.js @@ -31,6 +31,21 @@ class NotificationErrorLogController { } } + // Get notification error logs by notification_error_id + static async getByNotificationErrorId(req, res) { + try { + const { id } = req.params; + + const results = await NotificationErrorLogService.getNotificationErrorLogByNotificationErrorId(id); + const response = await setResponse(results, 'Notification Error Logs found') + + res.status(response.statusCode).json(response); + } catch (error) { + const response = await setResponse(error, error.message, error.statusCode || 500); + res.status(response.statusCode).json(response); + } + } + // Create notification error log static async create(req, res) { try { diff --git a/routes/notification_error_log.route.js b/routes/notification_error_log.route.js index 908d64f..ce5e0f1 100644 --- a/routes/notification_error_log.route.js +++ b/routes/notification_error_log.route.js @@ -12,4 +12,7 @@ router.route("/") router.route("/:id") .get(verifyToken.verifyAccessToken, NotificationErrorLogController.getById); +router.route("/notification_error/:id") + .get(verifyToken.verifyAccessToken, NotificationErrorLogController.getByNotificationErrorId); + module.exports = router; \ No newline at end of file diff --git a/services/notification_error.service.js b/services/notification_error.service.js index efb46d1..8ca77d5 100644 --- a/services/notification_error.service.js +++ b/services/notification_error.service.js @@ -14,6 +14,7 @@ const { const { getAllNotificationErrorLogDb, + getNotificationErrorLogByNotificationErrorIdDb, } = require('../db/notification_error_log.db'); const { getFileUploadByPathDb } = require('../db/file_uploads.db'); @@ -78,8 +79,7 @@ class NotificationService { } // Get activity logs for this notification - const activityLogs = (await getAllNotificationErrorLogDb()) || []; - const notificationLogs = activityLogs.filter(log => log.notification_error_id === parseInt(id)); + const notificationLogs = (await getNotificationErrorLogByNotificationErrorIdDb(id)) || []; notification.activity_logs = notificationLogs; diff --git a/services/notification_error_log.service.js b/services/notification_error_log.service.js index ef69037..45d9f58 100644 --- a/services/notification_error_log.service.js +++ b/services/notification_error_log.service.js @@ -59,6 +59,17 @@ class NotificationErrorLogService { } } + // Get Notification Error Log by notification_error_id + static async getNotificationErrorLogByNotificationErrorId(notificationErrorId) { + try { + const results = await getNotificationErrorLogByNotificationErrorIdDb(notificationErrorId); + + return results; + } catch (error) { + throw new ErrorHandler(error.statusCode, error.message); + } + } + // Soft delete Notification Error Log static async deleteNotificationErrorLog(id, userId) { try {