misc fixes, GET user (with tests), more comments for preenHistory

This commit is contained in:
Matteo Pagliazzi
2015-12-13 20:08:14 +01:00
parent e6d9c978f7
commit a34f41f0f7
5 changed files with 99 additions and 18 deletions

View File

@@ -0,0 +1,33 @@
import { authWithHeaders } from '../../middlewares/api-v3/auth';
import common from '../../../../common';
let api = {};
/**
* @api {get} /user Get the authenticated user's profile
* @apiVersion 3.0.0
* @apiName UserGet
* @apiGroup User
*
* @apiSuccess {Object} user The user object
*/
api.getUser = {
method: 'GET',
middlewares: [authWithHeaders()],
url: '/user',
handler (req, res) {
let user = res.locals.user.toJSON();
// Remove apiToken from resonse TODO make it priavte at the user level? returned in signup/login
delete user.apiToken;
// TODO move to model (maybe virtuals, maybe in toJSON)
user.stats.toNextLevel = common.tnl(user.stats.lvl);
user.stats.maxHealth = common.maxHealth;
user.stats.maxMP = res.locals.user._statsComputed.maxMP;
return res.json(200, user);
},
};
export default api;