NotificationsController.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. Notifications = require("./Notifications")
  2. logger = require("logger-sharelatex")
  3. metrics = require('metrics-sharelatex')
  4. module.exports =
  5. getUserNotifications: (req, res)->
  6. logger.log user_id: req.params.user_id, "getting user unread notifications"
  7. metrics.inc "getUserNotifications"
  8. Notifications.getUserNotifications req.params.user_id, (err, notifications)->
  9. res.json(notifications)
  10. addNotification: (req, res)->
  11. logger.log user_id: req.params.user_id, notification:req.body, "adding notification"
  12. metrics.inc "addNotification"
  13. Notifications.addNotification req.params.user_id, req.body, (err, notifications)->
  14. if err?
  15. res.send 500
  16. else
  17. res.send()
  18. removeNotificationId: (req, res)->
  19. logger.log user_id: req.params.user_id, notification_id: req.params.notification_id, "mark id notification as read"
  20. metrics.inc "removeNotificationId"
  21. Notifications.removeNotificationId req.params.user_id, req.params.notification_id, (err, notifications)->
  22. res.send()
  23. removeNotificationKey: (req, res)->
  24. logger.log user_id: req.params.user_id, notification_key: req.body.key, "mark key notification as read"
  25. metrics.inc "removeNotificationKey"
  26. Notifications.removeNotificationKey req.params.user_id, req.body.key, (err, notifications)->
  27. res.send()
  28. removeNotificationByKeyOnly: (req, res)->
  29. notification_key = req.params.key
  30. logger.log {notification_key}, "mark notification as read by key only"
  31. metrics.inc "removeNotificationKey"
  32. Notifications.removeNotificationByKeyOnly notification_key, (err, notifications)->
  33. res.send()