add: reader in notification detail & update notification
This commit is contained in:
@@ -2,6 +2,8 @@ const {
|
||||
getAllNotificationDb,
|
||||
getNotificationByIdDb,
|
||||
InsertNotificationErrorDb,
|
||||
getReaderNotificationErrorDb,
|
||||
updateNotificationErrorDb,
|
||||
} = require('../db/notification_error.db');
|
||||
|
||||
const {
|
||||
@@ -62,6 +64,8 @@ class NotificationService {
|
||||
throw new ErrorHandler(404, 'Notification not found');
|
||||
}
|
||||
|
||||
const readerNotification = (await getReaderNotificationErrorDb(id))|| [];
|
||||
|
||||
// Get error code details if error_code_id exists
|
||||
if (notification.error_code_id) {
|
||||
const errorCode = await getErrorCodeByIdDb(notification.error_code_id);
|
||||
@@ -70,7 +74,7 @@ class NotificationService {
|
||||
// Get solutions for this error code
|
||||
const solutions = (await getSolutionsByErrorCodeIdDb(errorCode.error_code_id)) || [];
|
||||
|
||||
const spareparts = await getSparepartsByErrorCodeIdDb(errorCode.error_code_id);
|
||||
const spareparts = (await getSparepartsByErrorCodeIdDb(errorCode.error_code_id)) || [];
|
||||
|
||||
const solutionsWithDetails = await Promise.all(
|
||||
solutions.map(async (solution) => {
|
||||
@@ -94,7 +98,7 @@ class NotificationService {
|
||||
notification.error_code = {
|
||||
...errorCode,
|
||||
solution: solutionsWithDetails,
|
||||
spareparts: spareparts
|
||||
spareparts: spareparts,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -102,6 +106,8 @@ class NotificationService {
|
||||
// Get activity logs for this notification
|
||||
const notificationLogs = (await getNotificationErrorLogByNotificationErrorIdDb(id)) || [];
|
||||
|
||||
notification.reader = readerNotification;
|
||||
|
||||
notification.activity_logs = notificationLogs;
|
||||
|
||||
return notification;
|
||||
@@ -109,6 +115,24 @@ class NotificationService {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async updateNotificationError(id, data) {
|
||||
try {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
const dataExist = await getNotificationByIdDb(id);
|
||||
|
||||
if (dataExist.length < 1) {
|
||||
throw new ErrorHandler(404, 'NotificationErrorUser not found');
|
||||
}
|
||||
|
||||
const result = await updateNotificationErrorDb(id, data);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NotificationService;
|
||||
|
||||
Reference in New Issue
Block a user