feat: Nambahin feature notifikasi

This commit is contained in:
Rafi Athallah
2026-06-23 14:51:31 +07:00
parent 24a3ec7fd0
commit 0e9498a2d0
14 changed files with 1185 additions and 11 deletions
@@ -0,0 +1,77 @@
const notificationService = require('../services/notification.service');
const { response, error } = require('../../../helpers/utils/wrapper');
const { SUCCESS, ERROR } = require('../../../helpers/http-status/status_code');
const { InternalServerError } = require('../../../helpers/error');
const getActor = (req) => ({
id: req.id,
role: req.role,
email: req.email,
});
class NotificationController {
async getNotifications(req, res) {
try {
const actor = getActor(req);
const result = await notificationService.getNotifications(actor);
if (result.err) {
return response(res, 'fail', result);
}
return response(res, 'success', result, 'Notifications retrieved successfully', SUCCESS.OK);
} catch (err) {
return response(
res,
'fail',
error(new InternalServerError(err.message)),
'Unexpected error occurred',
ERROR.INTERNAL_ERROR
);
}
}
async markAsRead(req, res) {
try {
const actor = getActor(req);
const result = await notificationService.markAsRead(req.params.id, actor);
if (result.err) {
return response(res, 'fail', result);
}
return response(res, 'success', result, 'Notification marked as read successfully', SUCCESS.OK);
} catch (err) {
return response(
res,
'fail',
error(new InternalServerError(err.message)),
'Unexpected error occurred',
ERROR.INTERNAL_ERROR
);
}
}
async markAllAsRead(req, res) {
try {
const actor = getActor(req);
const result = await notificationService.markAllAsRead(actor);
if (result.err) {
return response(res, 'fail', result);
}
return response(res, 'success', result, 'All notifications marked as read', SUCCESS.OK);
} catch (err) {
return response(
res,
'fail',
error(new InternalServerError(err.message)),
'Unexpected error occurred',
ERROR.INTERNAL_ERROR
);
}
}
}
module.exports = new NotificationController();