2020-01-13 19:00:40 +00:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-01-13 19:00:33 +00: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 19:00:49 +00:00
|
|
|
const Notifications = require('./Notifications')
|
2021-12-14 13:00:35 +00:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-11-25 11:57:20 +00:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2016-01-14 12:35:16 +00:00
|
|
|
|
2020-01-13 19:00:33 +00:00
|
|
|
module.exports = {
|
2021-10-27 09:49:18 +00:00
|
|
|
getUserNotifications(req, res, next) {
|
2020-01-13 19:00:49 +00:00
|
|
|
logger.log(
|
|
|
|
{ user_id: req.params.user_id },
|
|
|
|
'getting user unread notifications'
|
|
|
|
)
|
|
|
|
metrics.inc('getUserNotifications')
|
|
|
|
return Notifications.getUserNotifications(
|
|
|
|
req.params.user_id,
|
2021-10-27 09:49:18 +00:00
|
|
|
(err, notifications) => {
|
|
|
|
if (err) return next(err)
|
|
|
|
res.json(notifications)
|
|
|
|
}
|
2020-01-13 19:00:49 +00:00
|
|
|
)
|
|
|
|
},
|
2016-01-14 12:35:16 +00:00
|
|
|
|
2020-01-13 19:00:49 +00:00
|
|
|
addNotification(req, res) {
|
|
|
|
logger.log(
|
|
|
|
{ user_id: req.params.user_id, notification: req.body },
|
|
|
|
'adding notification'
|
|
|
|
)
|
|
|
|
metrics.inc('addNotification')
|
2020-06-04 07:50:05 +00: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 19:00:49 +00:00
|
|
|
}
|
2020-06-04 07:50:05 +00:00
|
|
|
)
|
2020-01-13 19:00:49 +00:00
|
|
|
},
|
2016-01-14 12:35:16 +00:00
|
|
|
|
2021-10-27 09:49:18 +00:00
|
|
|
removeNotificationId(req, res, next) {
|
2020-01-13 19:00:49 +00:00
|
|
|
logger.log(
|
|
|
|
{
|
|
|
|
user_id: req.params.user_id,
|
2021-07-13 11:04:44 +00:00
|
|
|
notification_id: req.params.notification_id,
|
2020-01-13 19:00:49 +00:00
|
|
|
},
|
|
|
|
'mark id notification as read'
|
|
|
|
)
|
|
|
|
metrics.inc('removeNotificationId')
|
|
|
|
return Notifications.removeNotificationId(
|
|
|
|
req.params.user_id,
|
|
|
|
req.params.notification_id,
|
2021-10-27 09:49:18 +00:00
|
|
|
err => {
|
|
|
|
if (err) return next(err)
|
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
2020-01-13 19:00:49 +00:00
|
|
|
)
|
|
|
|
},
|
2016-01-14 12:35:16 +00:00
|
|
|
|
2021-10-27 09:49:18 +00:00
|
|
|
removeNotificationKey(req, res, next) {
|
2020-01-13 19:00:49 +00:00
|
|
|
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,
|
2021-10-27 09:49:18 +00:00
|
|
|
(err, notifications) => {
|
|
|
|
if (err) return next(err)
|
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
2020-01-13 19:00:49 +00:00
|
|
|
)
|
|
|
|
},
|
2016-02-05 09:38:32 +00:00
|
|
|
|
2021-10-27 09:49:18 +00:00
|
|
|
removeNotificationByKeyOnly(req, res, next) {
|
2020-01-13 19:00:49 +00:00
|
|
|
const notification_key = req.params.key
|
|
|
|
logger.log({ notification_key }, 'mark notification as read by key only')
|
|
|
|
metrics.inc('removeNotificationKey')
|
2021-10-27 09:49:18 +00:00
|
|
|
return Notifications.removeNotificationByKeyOnly(notification_key, err => {
|
|
|
|
if (err) return next(err)
|
|
|
|
res.sendStatus(200)
|
|
|
|
})
|
2021-07-13 11:04:44 +00:00
|
|
|
},
|
2021-10-20 10:18:14 +00:00
|
|
|
|
|
|
|
countNotificationsByKeyOnly(req, res) {
|
|
|
|
const notificationKey = req.params.key
|
|
|
|
Notifications.countNotificationsByKeyOnly(notificationKey, (err, count) => {
|
|
|
|
if (err) {
|
|
|
|
logger.err({ err, notificationKey }, 'cannot count by key')
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
res.json({ count })
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteUnreadNotificationsByKeyOnlyBulk(req, res) {
|
|
|
|
const notificationKey = req.params.key
|
|
|
|
Notifications.deleteUnreadNotificationsByKeyOnlyBulk(
|
|
|
|
notificationKey,
|
|
|
|
(err, count) => {
|
|
|
|
if (err) {
|
|
|
|
logger.err({ err, notificationKey }, 'cannot bulk remove by key')
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
res.json({ count })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
2020-01-13 19:00:49 +00:00
|
|
|
}
|