NotificationsController.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. max-len,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const NotificationsHandler = require('./NotificationsHandler')
  14. const AuthenticationController = require('../Authentication/AuthenticationController')
  15. const _ = require('underscore')
  16. module.exports = {
  17. getAllUnreadNotifications(req, res) {
  18. const user_id = AuthenticationController.getLoggedInUserId(req)
  19. return NotificationsHandler.getUserNotifications(user_id, function(
  20. err,
  21. unreadNotifications
  22. ) {
  23. unreadNotifications = _.map(unreadNotifications, function(notification) {
  24. notification.html = req.i18n.translate(
  25. notification.templateKey,
  26. notification.messageOpts
  27. )
  28. return notification
  29. })
  30. return res.send(unreadNotifications)
  31. })
  32. },
  33. markNotificationAsRead(req, res) {
  34. const user_id = AuthenticationController.getLoggedInUserId(req)
  35. const { notification_id } = req.params
  36. NotificationsHandler.markAsRead(user_id, notification_id, () =>
  37. res.sendStatus(200)
  38. )
  39. }
  40. }