f7be7205e7
* move remaining files frm /common/script/public to website/public * remove localstorage * add back noscript template and put all javascript in the footer * fixes client side tests * remove double quotes where possible * simplify jade code and add tests for buildManifest * loading page with logo and spinner * better loading screen in landscape mode * icon on top of text logo * wip: user.notifications * notifications: simpler and working code * finish implementing notifications * correct loading screen css and re-inline images * add tests for user notifications * split User model in multiple files * remove old comment about missing .catch() * correctly setup hooks and methods for User model. Cleanup localstorage * include UserNotificationsService in static page js and split loading-screen css in its own file * add cron notification and misc fixes * remove console.log * fix tests * fix multiple notifications
29 lines
875 B
JavaScript
29 lines
875 B
JavaScript
module.exports = function responseHandler (req, res, next) {
|
|
// Only used for successful responses
|
|
res.respond = function respond (status = 200, data = {}, message) {
|
|
let user = res.locals && res.locals.user;
|
|
|
|
let response = {
|
|
success: status < 400,
|
|
data,
|
|
};
|
|
|
|
if (message) response.message = message;
|
|
|
|
// When userV=Number (user version) query parameter is passed and a user is logged in,
|
|
// sends back the current user._v in the response so that the client
|
|
// can verify if it's the most up to date data.
|
|
// Considered part of the private API for now and not officially supported
|
|
if (user) {
|
|
response.notifications = user.notifications.map(notification => notification.toJSON());
|
|
if (req.query.userV) {
|
|
response.userV = user._v;
|
|
}
|
|
}
|
|
|
|
res.status(status).json(response);
|
|
};
|
|
|
|
next();
|
|
};
|