Start using req.resources = { app, volume, ...} pattern
Reason was that req.app was clashing with expressjs v5 which stores the main expressjs app object there
This commit is contained in:
@@ -21,14 +21,15 @@ async function load(req, res, next) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
if (!result) return next(new HttpError(404, 'Notification not found'));
|
||||
|
||||
req.notification = result;
|
||||
req.resources.notification = result;
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
function get(req, res, next) {
|
||||
assert.strictEqual(typeof req.notification, 'object');
|
||||
assert.strictEqual(typeof req.resources.notification, 'object');
|
||||
|
||||
next(new HttpSuccess(200, req.notification));
|
||||
next(new HttpSuccess(200, req.resources.notification));
|
||||
}
|
||||
|
||||
async function list(req, res, next) {
|
||||
@@ -40,7 +41,7 @@ async function list(req, res, next) {
|
||||
|
||||
if (req.query.acknowledged && !(req.query.acknowledged === 'true' || req.query.acknowledged === 'false')) return next(new HttpError(400, 'acknowledged must be a true or false'));
|
||||
|
||||
let filters = {};
|
||||
const filters = {};
|
||||
if (req.query.acknowledged) filters.acknowledged = req.query.acknowledged === 'true';
|
||||
|
||||
const [error, result] = await safe(notifications.list(filters, page, perPage));
|
||||
@@ -49,12 +50,12 @@ async function list(req, res, next) {
|
||||
}
|
||||
|
||||
async function update(req, res, next) {
|
||||
assert.strictEqual(typeof req.notification, 'object');
|
||||
assert.strictEqual(typeof req.resources.notification, 'object');
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.acknowledged !== 'boolean') return next(new HttpError(400, 'acknowledged must be a boolean'));
|
||||
|
||||
const [error] = await safe(notifications.update(req.notification, { acknowledged: req.body.acknowledged }));
|
||||
const [error] = await safe(notifications.update(req.resources.notification, { acknowledged: req.body.acknowledged }));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user