feat: Implement draft version of getBillingAndUsage query

This commit is contained in:
Faruk AYDIN
2023-03-25 00:39:49 +03:00
parent 310497a5bf
commit b5524b18cf
5 changed files with 80 additions and 1 deletions

View File

@@ -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;