NotificationsController.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const NotificationsHandler = require('./NotificationsHandler')
  2. const SessionManager = require('../Authentication/SessionManager')
  3. const _ = require('lodash')
  4. module.exports = {
  5. getAllUnreadNotifications(req, res, next) {
  6. const userId = SessionManager.getLoggedInUserId(req.session)
  7. NotificationsHandler.getUserNotifications(
  8. userId,
  9. function (err, unreadNotifications) {
  10. if (err) {
  11. return next(err)
  12. }
  13. unreadNotifications = _.map(
  14. unreadNotifications,
  15. function (notification) {
  16. notification.html = req.i18n.translate(
  17. notification.templateKey,
  18. notification.messageOpts
  19. )
  20. return notification
  21. }
  22. )
  23. res.json(unreadNotifications)
  24. }
  25. )
  26. },
  27. markNotificationAsRead(req, res) {
  28. const userId = SessionManager.getLoggedInUserId(req.session)
  29. const { notificationId } = req.params
  30. NotificationsHandler.markAsRead(userId, notificationId, () =>
  31. res.sendStatus(200)
  32. )
  33. },
  34. }