From a22db1a6a39a4dcfb95f6180af7eb10694c1899b Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 21 Mar 2024 01:52:38 +0100 Subject: [PATCH] Fix timing between billedLastAt and billPaidUntil (#952) --- api/resolvers/sub.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/resolvers/sub.js b/api/resolvers/sub.js index e7a63fa9..2ac36160 100644 --- a/api/resolvers/sub.js +++ b/api/resolvers/sub.js @@ -400,14 +400,15 @@ export default { async function createSub (parent, data, { me, models, lnd, hash, hmac }) { const { billingType } = data let billingCost = TERRITORY_COST_MONTHLY - let billPaidUntil = datePivot(new Date(), { months: 1 }) + const billedLastAt = new Date() + let billPaidUntil = datePivot(billedLastAt, { months: 1 }) if (billingType === 'ONCE') { billingCost = TERRITORY_COST_ONCE billPaidUntil = null } else if (billingType === 'YEARLY') { billingCost = TERRITORY_COST_YEARLY - billPaidUntil = datePivot(new Date(), { years: 1 }) + billPaidUntil = datePivot(billedLastAt, { years: 1 }) } const cost = BigInt(1000) * BigInt(billingCost) @@ -429,6 +430,7 @@ async function createSub (parent, data, { me, models, lnd, hash, hmac }) { models.sub.create({ data: { ...data, + billedLastAt, billPaidUntil, billingCost, rankingType: 'WOT',