Merge pull request #1040 from automatisch/usage-data
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;
|
||||
|
19
packages/backend/src/graphql/queries/get-trial-status.ee.ts
Normal file
19
packages/backend/src/graphql/queries/get-trial-status.ee.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import appConfig from '../../config/app';
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
const getTrialStatus = async (
|
||||
_parent: unknown,
|
||||
_params: unknown,
|
||||
context: Context
|
||||
) => {
|
||||
if (!appConfig.isCloud) return;
|
||||
|
||||
const inTrial = await context.currentUser.inTrial();
|
||||
if (!inTrial) return;
|
||||
|
||||
return {
|
||||
expireAt: context.currentUser.trialExpiryDate,
|
||||
};
|
||||
};
|
||||
|
||||
export default getTrialStatus;
|
@@ -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,
|
||||
};
|
||||
|
||||
|
@@ -17,6 +17,7 @@ import getPaddleInfo from './queries/get-paddle-info.ee';
|
||||
import getBillingAndUsage from './queries/get-billing-and-usage.ee';
|
||||
import getInvoices from './queries/get-invoices.ee';
|
||||
import getAutomatischInfo from './queries/get-automatisch-info';
|
||||
import getTrialStatus from './queries/get-trial-status.ee';
|
||||
import healthcheck from './queries/healthcheck';
|
||||
|
||||
const queryResolvers = {
|
||||
@@ -39,6 +40,7 @@ const queryResolvers = {
|
||||
getBillingAndUsage,
|
||||
getInvoices,
|
||||
getAutomatischInfo,
|
||||
getTrialStatus,
|
||||
healthcheck,
|
||||
};
|
||||
|
||||
|
@@ -40,6 +40,7 @@ type Query {
|
||||
getBillingAndUsage: GetBillingAndUsage
|
||||
getInvoices: [Invoice]
|
||||
getAutomatischInfo: GetAutomatischInfo
|
||||
getTrialStatus: GetTrialStatus
|
||||
healthcheck: AppHealth
|
||||
}
|
||||
|
||||
@@ -475,6 +476,10 @@ type GetAutomatischInfo {
|
||||
isCloud: Boolean
|
||||
}
|
||||
|
||||
type GetTrialStatus {
|
||||
expireAt: String
|
||||
}
|
||||
|
||||
type GetBillingAndUsage {
|
||||
subscription: Subscription
|
||||
usage: Usage
|
||||
|
Reference in New Issue
Block a user