NotificationsController.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const Notifications = require('./Notifications')
  14. const logger = require('logger-sharelatex')
  15. const metrics = require('metrics-sharelatex')
  16. module.exports = {
  17. getUserNotifications(req, res) {
  18. logger.log(
  19. { user_id: req.params.user_id },
  20. 'getting user unread notifications'
  21. )
  22. metrics.inc('getUserNotifications')
  23. return Notifications.getUserNotifications(
  24. req.params.user_id,
  25. (err, notifications) => res.json(notifications)
  26. )
  27. },
  28. addNotification(req, res) {
  29. logger.log(
  30. { user_id: req.params.user_id, notification: req.body },
  31. 'adding notification'
  32. )
  33. metrics.inc('addNotification')
  34. return Notifications.addNotification(req.params.user_id, req.body, function(
  35. err,
  36. notifications
  37. ) {
  38. if (err != null) {
  39. return res.send(500)
  40. } else {
  41. return res.send()
  42. }
  43. })
  44. },
  45. removeNotificationId(req, res) {
  46. logger.log(
  47. {
  48. user_id: req.params.user_id,
  49. notification_id: req.params.notification_id
  50. },
  51. 'mark id notification as read'
  52. )
  53. metrics.inc('removeNotificationId')
  54. return Notifications.removeNotificationId(
  55. req.params.user_id,
  56. req.params.notification_id,
  57. (err, notifications) => res.send()
  58. )
  59. },
  60. removeNotificationKey(req, res) {
  61. logger.log(
  62. { user_id: req.params.user_id, notification_key: req.body.key },
  63. 'mark key notification as read'
  64. )
  65. metrics.inc('removeNotificationKey')
  66. return Notifications.removeNotificationKey(
  67. req.params.user_id,
  68. req.body.key,
  69. (err, notifications) => res.send()
  70. )
  71. },
  72. removeNotificationByKeyOnly(req, res) {
  73. const notification_key = req.params.key
  74. logger.log({ notification_key }, 'mark notification as read by key only')
  75. metrics.inc('removeNotificationKey')
  76. return Notifications.removeNotificationByKeyOnly(
  77. notification_key,
  78. (err, notifications) => res.send()
  79. )
  80. }
  81. }