NotificationsController.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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({user_id: req.params.user_id}, "getting user unread notifications");
  19. metrics.inc("getUserNotifications");
  20. return Notifications.getUserNotifications(req.params.user_id, (err, notifications)=> res.json(notifications));
  21. },
  22. addNotification(req, res){
  23. logger.log({user_id: req.params.user_id, notification:req.body}, "adding notification");
  24. metrics.inc("addNotification");
  25. return Notifications.addNotification(req.params.user_id, req.body, function(err, notifications){
  26. if (err != null) {
  27. return res.send(500);
  28. } else {
  29. return res.send();
  30. }
  31. });
  32. },
  33. removeNotificationId(req, res){
  34. logger.log({user_id: req.params.user_id, notification_id: req.params.notification_id}, "mark id notification as read");
  35. metrics.inc("removeNotificationId");
  36. return Notifications.removeNotificationId(req.params.user_id, req.params.notification_id, (err, notifications)=> res.send());
  37. },
  38. removeNotificationKey(req, res){
  39. logger.log({user_id: req.params.user_id, notification_key: req.body.key}, "mark key notification as read");
  40. metrics.inc("removeNotificationKey");
  41. return Notifications.removeNotificationKey(req.params.user_id, req.body.key, (err, notifications)=> res.send());
  42. },
  43. removeNotificationByKeyOnly(req, res){
  44. const notification_key = req.params.key;
  45. logger.log({notification_key}, "mark notification as read by key only");
  46. metrics.inc("removeNotificationKey");
  47. return Notifications.removeNotificationByKeyOnly(notification_key, (err, notifications)=> res.send());
  48. }
  49. };