Add field to track when current subscription type started

This commit is contained in:
Phillip Thelen
2022-11-08 12:38:24 +01:00
parent 3a34aa4cc5
commit 8d732c59c4
3 changed files with 56 additions and 1 deletions
@@ -161,6 +161,7 @@ async function prepareSubscriptionValues (data) {
plan.dateTerminated = moment().add({ months }).toDate();
plan.dateCreated = today;
}
plan.dateCurrentTypeCreated = today;
}
if (!plan.customerId) {
@@ -177,6 +178,7 @@ async function prepareSubscriptionValues (data) {
planId: block.key,
customerId: data.customerId,
dateUpdated: today,
dateCurrentTypeCreated: today,
paymentMethod: data.paymentMethod,
extraMonths: Number(plan.extraMonths) + _dateDiff(today, plan.dateTerminated),
dateTerminated: null,
@@ -13,6 +13,7 @@ export const schema = new mongoose.Schema({
dateCreated: Date,
dateTerminated: Date,
dateUpdated: Date,
dateCurrentTypeCreated: Date,
extraMonths: { $type: Number, default: 0 },
gemsBought: { $type: Number, default: 0 },
mysteryItems: { $type: Array, default: () => [] },