Files
overleaf-cep/services/web/app/src/Features/Notifications/NotificationsController.mjs
Andrew Rumble c6c62088cc Migrate Features to ES modules
GitOrigin-RevId: 4e9d3176b4b5a5504afc102e569a27d7788864a3
2024-10-17 08:06:08 +00:00

37 lines
1.0 KiB
JavaScript

import NotificationsHandler from './NotificationsHandler.js'
import SessionManager from '../Authentication/SessionManager.js'
import _ from 'lodash'
export default {
getAllUnreadNotifications(req, res, next) {
const userId = SessionManager.getLoggedInUserId(req.session)
NotificationsHandler.getUserNotifications(
userId,
function (err, unreadNotifications) {
if (err) {
return next(err)
}
unreadNotifications = _.map(
unreadNotifications,
function (notification) {
notification.html = req.i18n.translate(
notification.templateKey,
notification.messageOpts
)
return notification
}
)
res.json(unreadNotifications)
}
)
},
markNotificationAsRead(req, res) {
const userId = SessionManager.getLoggedInUserId(req.session)
const { notificationId } = req.params
NotificationsHandler.markAsRead(userId, notificationId, () =>
res.sendStatus(200)
)
},
}