2020-01-13 19:00:40 +00:00
|
|
|
// 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) {
|
2022-05-16 12:38:18 +00:00
|
|
|
logger.debug(
|
2023-03-16 12:38:09 +00:00
|
|
|
{ userId: req.params.user_id },
|
2020-01-13 19:00:49 +00:00
|
|
|
'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) {
|
2022-05-16 12:38:18 +00:00
|
|
|
logger.debug(
|
2023-03-16 12:38:09 +00:00
|
|
|
{ userId: req.params.user_id, notification: req.body },
|
2020-01-13 19:00:49 +00:00
|
|
|
'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) {
|
2022-05-16 12:38:18 +00:00
|
|
|
logger.debug(
|
2020-01-13 19:00:49 +00:00
|
|
|
{
|
2023-03-16 12:38:09 +00:00
|
|
|
userId: req.params.user_id,
|
|
|
|
notificationId: 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) {
|
2022-05-16 12:38:18 +00:00
|
|
|
logger.debug(
|
2023-03-16 12:38:09 +00:00
|
|
|
{ userId: req.params.user_id, notificationKey: req.body.key },
|
2020-01-13 19:00:49 +00:00
|
|
|
'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) {
|
2023-03-16 12:38:09 +00:00
|
|
|
const notificationKey = req.params.key
|
|
|
|
logger.debug({ notificationKey }, 'mark notification as read by key only')
|
2020-01-13 19:00:49 +00:00
|
|
|
metrics.inc('removeNotificationKey')
|
2023-03-16 12:38:09 +00:00
|
|
|
return Notifications.removeNotificationByKeyOnly(notificationKey, err => {
|
2021-10-27 09:49:18 +00:00
|
|
|
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
|
|
|
}
|