feat: Implement plan and usage API endpoint

This commit is contained in:
Faruk AYDIN
2024-03-15 00:49:15 +01:00
parent d984a3f275
commit 17bd2bf2ba
5 changed files with 123 additions and 0 deletions

View File

@@ -255,6 +255,31 @@ class User extends Base {
return currentUsageData.consumedTaskCount < plan.quota;
}
async getPlanAndUsage() {
const usageData = await this.$relatedQuery(
'currentUsageData'
).throwIfNotFound();
const subscription = await this.$relatedQuery('currentSubscription');
const currentPlan = Billing.paddlePlans.find(
(plan) => plan.productId === subscription?.paddlePlanId
);
const planAndUsage = {
usage: {
task: usageData.consumedTaskCount,
},
plan: {
id: subscription?.paddlePlanId || null,
name: subscription ? currentPlan.name : 'Free Trial',
limit: currentPlan?.limit || null,
},
};
return planAndUsage;
}
async getInvoices() {
const subscription = await this.$relatedQuery('currentSubscription');