NotificationsController.js 1002 B

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