mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix(v3): cleanup of shared code
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module.exports = function clearPMs (user) {
|
module.exports = function clearPMs (user) {
|
||||||
user.inbox.messages = {};
|
user.inbox.messages = {};
|
||||||
user.markModified('inbox.messages');
|
user.markModified('inbox.messages');
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
|
import updateStats from '../fns/updateStats';
|
||||||
|
|
||||||
const MAX_TASK_VALUE = 21.27;
|
const MAX_TASK_VALUE = 21.27;
|
||||||
const MIN_TASK_VALUE = -47.27;
|
const MIN_TASK_VALUE = -47.27;
|
||||||
@@ -254,6 +255,6 @@ module.exports = function scoreTask (options = {}, req = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.fns.updateStats(stats, req);
|
updateStats(user, stats, req);
|
||||||
return delta;
|
return delta;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ module.exports = function unlock (user, req = {}, analytics) {
|
|||||||
cost = 0.5;
|
cost = 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
let alreadyOwns = !isFullSet && user.fns.dotGet(`purchased.${path}`) === true;
|
let alreadyOwns = !isFullSet && _.get(user, `purchased.${path}`) === true;
|
||||||
|
|
||||||
if ((!user.balance || user.balance < cost) && !alreadyOwns) {
|
if ((!user.balance || user.balance < cost) && !alreadyOwns) {
|
||||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ api.score = function(req, res, next) {
|
|||||||
task,
|
task,
|
||||||
direction,
|
direction,
|
||||||
}, req);
|
}, req);
|
||||||
|
// Drop system (don't run on the client, as it would only be discarded since ops are sent to the API, not the results)
|
||||||
|
if (direction === 'up') user.fns.randomDrop({task, delta}, req);
|
||||||
|
|
||||||
asyncM.parallel({
|
asyncM.parallel({
|
||||||
task: task.save.bind(task),
|
task: task.save.bind(task),
|
||||||
|
|||||||
Reference in New Issue
Block a user