mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
misc fixes, GET user (with tests), more comments for preenHistory
This commit is contained in:
33
website/src/controllers/api-v3/user.js
Normal file
33
website/src/controllers/api-v3/user.js
Normal 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;
|
||||
Reference in New Issue
Block a user