mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Merge pull request #7042 from TheHollidayInn/api-v3-ops-reroll
Ported reroll. Added unit tests. Added reroll route. Added integration tests
This commit is contained in:
@@ -128,6 +128,7 @@ import sell from './ops/sell';
|
||||
import unlock from './ops/unlock';
|
||||
import revive from './ops/revive';
|
||||
import rebirth from './ops/rebirth';
|
||||
import reroll from './ops/reroll';
|
||||
|
||||
api.ops = {
|
||||
scoreTask,
|
||||
@@ -157,6 +158,7 @@ api.ops = {
|
||||
unlock,
|
||||
revive,
|
||||
rebirth,
|
||||
reroll,
|
||||
};
|
||||
|
||||
import handleTwoHanded from './fns/handleTwoHanded';
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function releaseBoth (user, req = {}, analytics) {
|
||||
let animal;
|
||||
@@ -20,15 +21,15 @@ module.exports = function releaseBoth (user, req = {}, analytics) {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 6,
|
||||
category: 'behavior'
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
user.balance -= 1.5;
|
||||
}
|
||||
|
||||
user.items.currentMount = "";
|
||||
user.items.currentPet = "";
|
||||
user.items.currentMount = '';
|
||||
user.items.currentPet = '';
|
||||
|
||||
for (animal in content.pets) {
|
||||
if (user.items.pets[animal] === -1) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function releaseMounts (user, req = {}, analytics) {
|
||||
let mount;
|
||||
@@ -29,7 +30,7 @@ module.exports = function releaseMounts (user, req = {}, analytics) {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior'
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function releasePets (user, req = {}, analytics) {
|
||||
if (user.balance < 1) {
|
||||
@@ -27,7 +28,7 @@ module.exports = function releasePets (user, req = {}, analytics) {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior'
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,36 @@
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
|
||||
module.exports = function(user, req, cb, analytics) {
|
||||
var analyticsData;
|
||||
module.exports = function reroll (user, tasks = [], req = {}, analytics) {
|
||||
if (user.balance < 1) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 401,
|
||||
message: i18n.t('notEnoughGems', req.language)
|
||||
}) : void 0;
|
||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||
}
|
||||
|
||||
user.balance--;
|
||||
_.each(user.tasks, function(task) {
|
||||
user.stats.hp = 50;
|
||||
|
||||
_.each(tasks, function resetTaskValues (task) {
|
||||
if (task.type !== 'reward') {
|
||||
return task.value = 0;
|
||||
task.value = 0;
|
||||
}
|
||||
});
|
||||
user.stats.hp = 50;
|
||||
analyticsData = {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior'
|
||||
};
|
||||
if (analytics != null) {
|
||||
analytics.track('Fortify Potion', analyticsData);
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('Fortify Potion', {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, user) : void 0;
|
||||
|
||||
let response = {
|
||||
data: {user, tasks},
|
||||
message: i18n.t('rerollComplete'),
|
||||
};
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user