mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Add Transaction log for gem and hourglass changes (#13589)
* 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>
This commit is contained in:
@@ -58,7 +58,7 @@ const CLEAR_BUFFS = {
|
||||
streaks: false,
|
||||
};
|
||||
|
||||
function grantEndOfTheMonthPerks (user, now) {
|
||||
async function grantEndOfTheMonthPerks (user, now) {
|
||||
// multi-month subscriptions are for multiples of 3 months
|
||||
const SUBSCRIPTION_BASIC_BLOCK_LENGTH = 3;
|
||||
const { plan } = user.purchased;
|
||||
@@ -135,7 +135,8 @@ function grantEndOfTheMonthPerks (user, now) {
|
||||
plan.consecutive.offset = planMonthsLength - 1;
|
||||
}
|
||||
if (perkAmountNeeded > 0) {
|
||||
plan.consecutive.trinkets += perkAmountNeeded; // one Hourglass every 3 months
|
||||
// one Hourglass every 3 months
|
||||
await plan.updateHourglasses(user._id, perkAmountNeeded, 'subscription_perks'); // eslint-disable-line no-await-in-loop
|
||||
plan.consecutive.gemCapExtra += 5 * perkAmountNeeded; // 5 extra Gems every 3 months
|
||||
// cap it at 50 (hard 25 limit + extra 25)
|
||||
if (plan.consecutive.gemCapExtra > 25) plan.consecutive.gemCapExtra = 25;
|
||||
@@ -279,7 +280,7 @@ function awardLoginIncentives (user) {
|
||||
}
|
||||
|
||||
// Perform various beginning-of-day reset actions.
|
||||
export function cron (options = {}) {
|
||||
export async function cron (options = {}) {
|
||||
const {
|
||||
user, tasksByType, analytics, now = new Date(), daysMissed, timezoneUtcOffsetFromUserPrefs,
|
||||
} = options;
|
||||
@@ -304,7 +305,7 @@ export function cron (options = {}) {
|
||||
}
|
||||
|
||||
if (user.isSubscribed()) {
|
||||
grantEndOfTheMonthPerks(user, now);
|
||||
await grantEndOfTheMonthPerks(user, now);
|
||||
}
|
||||
|
||||
const { plan } = user.purchased;
|
||||
|
||||
Reference in New Issue
Block a user