feat: Implement draft version of getBillingAndUsage query
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import Context from '../../types/express/context';
|
||||
import Billing from '../../helpers/billing/index.ee';
|
||||
|
||||
type Subscription = {
|
||||
monthlyQuota: string;
|
||||
status: string;
|
||||
nextBillDate: string;
|
||||
nextBillAmount: string;
|
||||
updateUrl: string;
|
||||
cancelUrl: string;
|
||||
};
|
||||
|
||||
const getBillingAndUsage = async (
|
||||
_parent: unknown,
|
||||
_params: unknown,
|
||||
context: Context
|
||||
) => {
|
||||
const persistedSubscription = await context.currentUser.$relatedQuery(
|
||||
'subscription'
|
||||
);
|
||||
|
||||
let subscription: Subscription;
|
||||
|
||||
if (persistedSubscription) {
|
||||
const currentPlan = Billing.paddlePlans.find(
|
||||
(plan) => plan.productId === persistedSubscription.paddlePlanId
|
||||
);
|
||||
|
||||
subscription = {
|
||||
monthlyQuota: currentPlan.limit,
|
||||
status: persistedSubscription.status,
|
||||
nextBillDate: persistedSubscription.nextBillDate,
|
||||
nextBillAmount: '€' + persistedSubscription.nextBillAmount,
|
||||
updateUrl: persistedSubscription.updateUrl,
|
||||
cancelUrl: persistedSubscription.cancelUrl,
|
||||
};
|
||||
} else {
|
||||
subscription = {
|
||||
monthlyQuota: 'Free trial',
|
||||
status: null,
|
||||
nextBillDate: '---',
|
||||
nextBillAmount: '---',
|
||||
updateUrl: null,
|
||||
cancelUrl: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
subscription,
|
||||
};
|
||||
};
|
||||
|
||||
export default getBillingAndUsage;
|
@@ -14,6 +14,7 @@ import getCurrentUser from './queries/get-current-user';
|
||||
import getUsageData from './queries/get-usage-data.ee';
|
||||
import getPaymentPlans from './queries/get-payment-plans.ee';
|
||||
import getPaddleInfo from './queries/get-paddle-info.ee';
|
||||
import getBillingAndUsage from './queries/get-billing-and-usage.ee';
|
||||
import getAutomatischInfo from './queries/get-automatisch-info';
|
||||
import healthcheck from './queries/healthcheck';
|
||||
|
||||
@@ -34,6 +35,7 @@ const queryResolvers = {
|
||||
getUsageData,
|
||||
getPaymentPlans,
|
||||
getPaddleInfo,
|
||||
getBillingAndUsage,
|
||||
getAutomatischInfo,
|
||||
healthcheck,
|
||||
};
|
||||
|
@@ -37,6 +37,7 @@ type Query {
|
||||
getUsageData: GetUsageData
|
||||
getPaymentPlans: [PaymentPlan]
|
||||
getPaddleInfo: GetPaddleInfo
|
||||
getBillingAndUsage: GetBillingAndUsage
|
||||
getAutomatischInfo: GetAutomatischInfo
|
||||
healthcheck: AppHealth
|
||||
}
|
||||
@@ -472,6 +473,19 @@ type GetAutomatischInfo {
|
||||
isCloud: Boolean
|
||||
}
|
||||
|
||||
type GetBillingAndUsage {
|
||||
subscription: Subscription
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
monthlyQuota: String
|
||||
updateUrl: String
|
||||
cancelUrl: String
|
||||
status: String
|
||||
nextBillAmount: String
|
||||
nextBillDate: String
|
||||
}
|
||||
|
||||
type GetUsageData {
|
||||
name: String
|
||||
allowedTaskCount: Int
|
||||
|
Reference in New Issue
Block a user