NotificationsController.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * DS207: Consider shorter variations of null checks
  5. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  6. */
  7. const Notifications = require("./Notifications");
  8. const logger = require("logger-sharelatex");
  9. const metrics = require('metrics-sharelatex');
  10. module.exports = {
  11. getUserNotifications(req, res){
  12. logger.log({user_id: req.params.user_id}, "getting user unread notifications");
  13. metrics.inc("getUserNotifications");
  14. return Notifications.getUserNotifications(req.params.user_id, (err, notifications)=> res.json(notifications));
  15. },
  16. addNotification(req, res){
  17. logger.log({user_id: req.params.user_id, notification:req.body}, "adding notification");
  18. metrics.inc("addNotification");
  19. return Notifications.addNotification(req.params.user_id, req.body, function(err, notifications){
  20. if (err != null) {
  21. return res.send(500);
  22. } else {
  23. return res.send();
  24. }
  25. });
  26. },
  27. removeNotificationId(req, res){
  28. logger.log({user_id: req.params.user_id, notification_id: req.params.notification_id}, "mark id notification as read");
  29. metrics.inc("removeNotificationId");
  30. return Notifications.removeNotificationId(req.params.user_id, req.params.notification_id, (err, notifications)=> res.send());
  31. },
  32. removeNotificationKey(req, res){
  33. logger.log({user_id: req.params.user_id, notification_key: req.body.key}, "mark key notification as read");
  34. metrics.inc("removeNotificationKey");
  35. return Notifications.removeNotificationKey(req.params.user_id, req.body.key, (err, notifications)=> res.send());
  36. },
  37. removeNotificationByKeyOnly(req, res){
  38. const notification_key = req.params.key;
  39. logger.log({notification_key}, "mark notification as read by key only");
  40. metrics.inc("removeNotificationKey");
  41. return Notifications.removeNotificationByKeyOnly(notification_key, (err, notifications)=> res.send());
  42. }
  43. };