mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
handle upgrades and creations better
This commit is contained in:
committed by
Phillip Thelen
parent
e81a052f66
commit
c0c6657536
@@ -3,6 +3,9 @@ import validator from 'validator';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import { TransactionModel as Transaction } from './transaction';
|
||||
|
||||
// multi-month subscriptions are for multiples of 3 months
|
||||
const SUBSCRIPTION_BASIC_BLOCK_LENGTH = 3;
|
||||
|
||||
export const schema = new mongoose.Schema({
|
||||
planId: String,
|
||||
subscriptionId: String,
|
||||
@@ -49,6 +52,8 @@ schema.plugin(baseModel, {
|
||||
|
||||
schema.methods.incrementPerkCounterAndReward = async function incrementPerkCounterAndReward
|
||||
(userID, adding) {
|
||||
// if perkMonthCount wasn't used before, initialize it.
|
||||
if (!this.perkMonthCount) this.perkMonthCount = this.consecutive.count % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
||||
this.perkMonthCount += adding;
|
||||
|
||||
const perks = Math.floor(this.perkMonthCount / 3);
|
||||
|
||||
Reference in New Issue
Block a user