mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
27 lines
597 B
JavaScript
27 lines
597 B
JavaScript
import packageInfo from '../../../package.json';
|
|
|
|
export default function responseHandler (req, res, next) {
|
|
// Only used for successful responses
|
|
res.respond = function respond (status = 200, data = {}, message) {
|
|
const user = res.locals && res.locals.user;
|
|
|
|
const response = {
|
|
success: status < 400,
|
|
data,
|
|
};
|
|
|
|
if (message) response.message = message;
|
|
|
|
if (user) {
|
|
response.notifications = user.notifications;
|
|
response.userV = user._v;
|
|
}
|
|
|
|
response.appVersion = packageInfo.version;
|
|
|
|
res.status(status).json(response);
|
|
};
|
|
|
|
next();
|
|
}
|