mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Deprecate API v2 (#7761)
* deprecate api-v2 * remove v2 test helpers * remove unused string
This commit is contained in:
28
website/server/middlewares/response.js
Normal file
28
website/server/middlewares/response.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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();
|
||||
};
|
||||
Reference in New Issue
Block a user