notifications: can also mark it as unread

This commit is contained in:
Girish Ramakrishnan
2021-04-21 12:00:07 -07:00
parent bb3f9744fb
commit d437acebe2
5 changed files with 37 additions and 31 deletions
+7 -4
View File
@@ -4,7 +4,7 @@ exports = module.exports = {
verifyOwnership,
get,
list,
ack
update
};
let assert = require('assert'),
@@ -44,17 +44,20 @@ function list(req, res, next) {
const acknowledged = req.query.acknowledged ? req.query.acknowledged === 'true' : null;
notifications.listByUserIdPaged(req.user.id, { acknowledged }, page, perPage, function (error, result) {
notifications.list({ userId: req.user.id, acknowledged }, page, perPage, function (error, result) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { notifications: result }));
});
}
function ack(req, res, next) {
function update(req, res, next) {
assert.strictEqual(typeof req.params.notificationId, 'string');
assert.strictEqual(typeof req.body, 'object');
notifications.ack(req.params.notificationId, function (error) {
if (typeof req.body.acknowledged !== 'boolean') return next(new HttpError(400, 'acknowledged must be a booliean'));
notifications.update(req.params.notificationId, { acknowledged: req.body.acknowledged }, function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204, {}));