feat: add subscription update and cancel logics
This commit is contained in:
@@ -13,7 +13,7 @@ const getBillingAndUsage = async (
|
||||
context: Context
|
||||
) => {
|
||||
const persistedSubscription = await context.currentUser.$relatedQuery(
|
||||
'subscription'
|
||||
'currentSubscription'
|
||||
);
|
||||
|
||||
const subscription = persistedSubscription
|
||||
@@ -39,8 +39,8 @@ const paidSubscription = (subscription: Subscription): TSubscription => {
|
||||
title: currentPlan.limit,
|
||||
action: {
|
||||
type: 'link',
|
||||
text: 'Change plan',
|
||||
src: '/settings/billing/change-plan',
|
||||
text: 'Cancel plan',
|
||||
src: subscription.cancelUrl,
|
||||
},
|
||||
},
|
||||
nextBillAmount: {
|
||||
|
@@ -6,7 +6,7 @@ const getInvoices = async (
|
||||
_params: unknown,
|
||||
context: Context
|
||||
) => {
|
||||
const subscription = await context.currentUser.$relatedQuery('subscription');
|
||||
const subscription = await context.currentUser.$relatedQuery('currentSubscription');
|
||||
|
||||
if (!subscription) {
|
||||
return;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import appConfig from '../../config/app';
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
// TODO: remove as getBillingAndUsageData query has been introduced
|
||||
const getUsageData = async (
|
||||
_parent: unknown,
|
||||
_params: unknown,
|
||||
@@ -9,18 +10,20 @@ const getUsageData = async (
|
||||
if (!appConfig.isCloud) return;
|
||||
|
||||
const usageData = await context.currentUser
|
||||
.$relatedQuery('usageData')
|
||||
.$relatedQuery('currentUsageData')
|
||||
.throwIfNotFound();
|
||||
|
||||
const paymentPlan = await context.currentUser
|
||||
.$relatedQuery('paymentPlan')
|
||||
const subscription = await usageData
|
||||
.$relatedQuery('subscription')
|
||||
.throwIfNotFound();
|
||||
|
||||
const plan = subscription.plan;
|
||||
|
||||
const computedUsageData = {
|
||||
name: paymentPlan.name,
|
||||
allowedTaskCount: paymentPlan.taskCount,
|
||||
name: plan.name,
|
||||
allowedTaskCount: plan.quota,
|
||||
consumedTaskCount: usageData.consumedTaskCount,
|
||||
remainingTaskCount: paymentPlan.taskCount - usageData.consumedTaskCount,
|
||||
remainingTaskCount: plan.quota - usageData.consumedTaskCount,
|
||||
nextResetAt: usageData.nextResetAt,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user