mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* Log all gem transactions to database * Also store hourglass transactions * Fix tests * Display transaction history in hall of heroes for admins * add tests to new API call * hide transaction settings tab for non admins * fix(lint): remove console * fix(lint): various automatic corrections * fix(transactions): use enum expected pluralizations * fix api unit tests * fix lint * fix failing test * Fix minor inconsistencies * Log all gem transactions to database * Also store hourglass transactions * Fix tests * Display transaction history in hall of heroes for admins * add tests to new API call * hide transaction settings tab for non admins * fix(lint): remove console * fix(lint): various automatic corrections * fix(transactions): use enum expected pluralizations * fix api unit tests * fix lint * Fix minor inconsistencies Co-authored-by: Sabe Jones <sabrecat@gmail.com>
39 lines
854 B
JavaScript
39 lines
854 B
JavaScript
import each from 'lodash/each';
|
|
import i18n from '../i18n';
|
|
import {
|
|
NotAuthorized,
|
|
} from '../libs/errors';
|
|
import updateUserBalance from './updateUserBalance';
|
|
|
|
export default async function reroll (user, tasks = [], req = {}, analytics) {
|
|
if (user.balance < 1) {
|
|
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
|
}
|
|
|
|
await updateUserBalance(user, -1, 'reroll');
|
|
user.stats.hp = 50;
|
|
|
|
each(tasks, task => {
|
|
if (!task.challenge || !task.challenge.id || task.challenge.broken) {
|
|
if (task.type !== 'reward') {
|
|
task.value = 0;
|
|
}
|
|
}
|
|
});
|
|
|
|
if (analytics) {
|
|
analytics.track('Fortify Potion', {
|
|
uuid: user._id,
|
|
currency: 'Gems',
|
|
gemCost: 4,
|
|
category: 'behavior',
|
|
headers: req.headers,
|
|
});
|
|
}
|
|
|
|
return [
|
|
{ user, tasks },
|
|
i18n.t('fortifyComplete'),
|
|
];
|
|
}
|