NotificationsController.coffee 939 B

123456789101112131415161718192021
  1. NotificationsHandler = require("./NotificationsHandler")
  2. AuthenticationController = require("../Authentication/AuthenticationController")
  3. logger = require("logger-sharelatex")
  4. _ = require("underscore")
  5. module.exports =
  6. getAllUnreadNotifications: (req, res)->
  7. user_id = AuthenticationController.getLoggedInUserId(req)
  8. NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
  9. unreadNotifications = _.map unreadNotifications, (notification)->
  10. notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
  11. return notification
  12. res.send(unreadNotifications)
  13. markNotificationAsRead: (req, res)->
  14. user_id = AuthenticationController.getLoggedInUserId(req)
  15. notification_id = req.params.notification_id
  16. NotificationsHandler.markAsRead user_id, notification_id, ->
  17. res.send()
  18. logger.log user_id:user_id, notification_id:notification_id, "mark notification as read"