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:
Matteo Pagliazzi
2016-08-04 19:56:00 +02:00
committed by GitHub
parent d097868cad
commit d7ccf2bbe1
8 changed files with 96 additions and 17 deletions

View File

@@ -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);
},
};