mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Fix API early Stat Point allocation (#10680)
* Refactor hasClass check to common so it can be used in shared & server-side code * Check that user has selected class before allocating stat points
This commit is contained in:
committed by
Matteo Pagliazzi
parent
26c8323e70
commit
71c0939a15
@@ -8,6 +8,7 @@ import {
|
||||
} from '../../libs/errors';
|
||||
import i18n from '../../i18n';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import hasClass from '../../libs/hasClass';
|
||||
|
||||
module.exports = function allocate (user, req = {}) {
|
||||
let stat = get(req, 'query.stat', 'str');
|
||||
@@ -16,6 +17,10 @@ module.exports = function allocate (user, req = {}) {
|
||||
throw new BadRequest(errorMessage('invalidAttribute', {attr: stat}));
|
||||
}
|
||||
|
||||
if (!hasClass(user)) {
|
||||
throw new NotAuthorized(i18n.t('classNotSelected', req.language));
|
||||
}
|
||||
|
||||
if (user.stats.points > 0) {
|
||||
user.stats[stat]++;
|
||||
user.stats.points--;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '../../libs/errors';
|
||||
import i18n from '../../i18n';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import hasClass from '../../libs/hasClass';
|
||||
|
||||
module.exports = function allocateBulk (user, req = {}) {
|
||||
const stats = get(req, 'body.stats');
|
||||
@@ -21,6 +22,10 @@ module.exports = function allocateBulk (user, req = {}) {
|
||||
throw new BadRequest(errorMessage('invalidAttribute', {attr: invalidStats.join(',')}));
|
||||
}
|
||||
|
||||
if (!hasClass(user)) {
|
||||
throw new NotAuthorized(i18n.t('classNotSelected', req.language));
|
||||
}
|
||||
|
||||
if (user.stats.points <= 0) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughAttrPoints', req.language));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user