NotificationsController.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* eslint-disable
  2. camelcase,
  3. node/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(
  20. user_id,
  21. function (err, unreadNotifications) {
  22. unreadNotifications = _.map(
  23. unreadNotifications,
  24. function (notification) {
  25. notification.html = req.i18n.translate(
  26. notification.templateKey,
  27. notification.messageOpts
  28. )
  29. return notification
  30. }
  31. )
  32. return res.send(unreadNotifications)
  33. }
  34. )
  35. },
  36. markNotificationAsRead(req, res) {
  37. const user_id = AuthenticationController.getLoggedInUserId(req)
  38. const { notification_id } = req.params
  39. NotificationsHandler.markAsRead(user_id, notification_id, () =>
  40. res.sendStatus(200)
  41. )
  42. }
  43. }