Files
habitica/website/server/middlewares/response.js
Matteo Pagliazzi c6881c5e30 More Client Fixes (#9036)
* add automatic user syncing when user._v does not match with server

* fix google signup

* fixes to user sync

* check for next cron on activity

* add comment
2017-09-14 18:55:17 +02:00

23 lines
541 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;
if (user) {
response.notifications = user.notifications.map(notification => notification.toJSON());
response.userV = user._v;
}
res.status(status).json(response);
};
next();
};