mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
API: return computed stats for members routes (#7870)
* api: return computed stats for members responses * add integration tests for computed stats * add unit tests for computed stats * clarify test name * add missing query parameter to test case * reset test database before running API tests for the Hall
This commit is contained in:
@@ -30,19 +30,14 @@ api.getUser = {
|
||||
middlewares: [authWithHeaders()],
|
||||
url: '/user',
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user.toJSON();
|
||||
let user = res.locals.user;
|
||||
let userToJSON = user.toJSON();
|
||||
|
||||
// Remove apiToken from response TODO make it private at the user level? returned in signup/login
|
||||
delete user.apiToken;
|
||||
delete userToJSON.apiToken;
|
||||
|
||||
// TODO move to model? (maybe virtuals, maybe in toJSON)
|
||||
// NOTE: if an item is manually added to user.stats common/fns/predictableRandom must be tweaked
|
||||
// so it's not considered. Otherwise the client will have it while the server won't and the results will be different.
|
||||
user.stats.toNextLevel = common.tnl(user.stats.lvl);
|
||||
user.stats.maxHealth = common.maxHealth;
|
||||
user.stats.maxMP = common.statsComputed(user).maxMP;
|
||||
|
||||
return res.respond(200, user);
|
||||
user.addComputedStatsToJSONObj(userToJSON);
|
||||
return res.respond(200, userToJSON);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user