don’t give additional HG for new sub if they already got one this month

This commit is contained in:
Phillip Thelen
2024-10-14 15:59:40 +02:00
parent f14cb09026
commit 7a61c72b47
2 changed files with 5 additions and 1 deletions
@@ -260,7 +260,9 @@ async function createSubscription (data) {
recipient.purchased.plan.hourglassPromoReceived = new Date();
await plan.updateHourglasses(recipient._id, 12, 'subscription_bonus');
}
if (isNewSubscription) {
const { lastHourglassReceived } = recipient.purchased.plan.consecutive;
if (isNewSubscription
&& (lastHourglassReceived === null || lastHourglassReceived === undefined || !moment().isSame(lastHourglassReceived, 'month'))) {
await plan.updateHourglasses(recipient._id, 1, 'subscription_perks');
}
}
@@ -33,6 +33,7 @@ export const schema = new mongoose.Schema({
offset: { $type: Number, default: 0 },
gemCapExtra: { $type: Number, default: 0 },
trinkets: { $type: Number, default: 0 },
lastHourglassReceived: Date,
},
}, {
strict: true,
@@ -72,6 +73,7 @@ schema.methods.updateHourglasses = async function updateHourglasses (
referenceText,
) {
this.consecutive.trinkets += amount;
this.consecutive.lastHourglassReceived = new Date();
await Transaction.create({
currency: 'hourglasses',
userId,