2020-01-13 14:00:40 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-01-13 14:00:33 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-01-13 14:00:49 -05:00
|
|
|
const Notifications = require('./Notifications')
|
|
|
|
const logger = require('logger-sharelatex')
|
2020-11-25 06:57:20 -05:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2020-01-13 14:00:33 -05:00
|
|
|
module.exports = {
|
2020-01-13 14:00:49 -05:00
|
|
|
getUserNotifications(req, res) {
|
|
|
|
logger.log(
|
|
|
|
{ user_id: req.params.user_id },
|
|
|
|
'getting user unread notifications'
|
|
|
|
)
|
|
|
|
metrics.inc('getUserNotifications')
|
|
|
|
return Notifications.getUserNotifications(
|
|
|
|
req.params.user_id,
|
|
|
|
(err, notifications) => res.json(notifications)
|
|
|
|
)
|
|
|
|
},
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2020-01-13 14:00:49 -05:00
|
|
|
addNotification(req, res) {
|
|
|
|
logger.log(
|
|
|
|
{ user_id: req.params.user_id, notification: req.body },
|
|
|
|
'adding notification'
|
|
|
|
)
|
|
|
|
metrics.inc('addNotification')
|
2020-06-04 03:50:05 -04:00
|
|
|
return Notifications.addNotification(
|
|
|
|
req.params.user_id,
|
|
|
|
req.body,
|
|
|
|
function (err, notifications) {
|
|
|
|
if (err != null) {
|
|
|
|
return res.sendStatus(500)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(200)
|
|
|
|
}
|
2020-01-13 14:00:49 -05:00
|
|
|
}
|
2020-06-04 03:50:05 -04:00
|
|
|
)
|
2020-01-13 14:00:49 -05:00
|
|
|
},
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2020-01-13 14:00:49 -05:00
|
|
|
removeNotificationId(req, res) {
|
|
|
|
logger.log(
|
|
|
|
{
|
|
|
|
user_id: req.params.user_id,
|
2021-07-13 07:04:44 -04:00
|
|
|
notification_id: req.params.notification_id,
|
2020-01-13 14:00:49 -05:00
|
|
|
},
|
|
|
|
'mark id notification as read'
|
|
|
|
)
|
|
|
|
metrics.inc('removeNotificationId')
|
|
|
|
return Notifications.removeNotificationId(
|
|
|
|
req.params.user_id,
|
|
|
|
req.params.notification_id,
|
2020-03-18 11:29:28 -04:00
|
|
|
(err, notifications) => res.sendStatus(200)
|
2020-01-13 14:00:49 -05:00
|
|
|
)
|
|
|
|
},
|
2016-01-14 07:35:16 -05:00
|
|
|
|
2020-01-13 14:00:49 -05:00
|
|
|
removeNotificationKey(req, res) {
|
|
|
|
logger.log(
|
|
|
|
{ user_id: req.params.user_id, notification_key: req.body.key },
|
|
|
|
'mark key notification as read'
|
|
|
|
)
|
|
|
|
metrics.inc('removeNotificationKey')
|
|
|
|
return Notifications.removeNotificationKey(
|
|
|
|
req.params.user_id,
|
|
|
|
req.body.key,
|
2020-03-18 11:29:28 -04:00
|
|
|
(err, notifications) => res.sendStatus(200)
|
2020-01-13 14:00:49 -05:00
|
|
|
)
|
|
|
|
},
|
2016-02-05 04:38:32 -05:00
|
|
|
|
2020-01-13 14:00:49 -05:00
|
|
|
removeNotificationByKeyOnly(req, res) {
|
|
|
|
const notification_key = req.params.key
|
|
|
|
logger.log({ notification_key }, 'mark notification as read by key only')
|
|
|
|
metrics.inc('removeNotificationKey')
|
|
|
|
return Notifications.removeNotificationByKeyOnly(
|
|
|
|
notification_key,
|
2020-03-18 11:29:28 -04:00
|
|
|
(err, notifications) => res.sendStatus(200)
|
2020-01-13 14:00:49 -05:00
|
|
|
)
|
2021-07-13 07:04:44 -04:00
|
|
|
},
|
2020-01-13 14:00:49 -05:00
|
|
|
}
|