mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
* 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
23 lines
541 B
JavaScript
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();
|
|
};
|