feat: auto subscribe to free plan once signup on community version.

This commit is contained in:
Ahmed Bouhuolia
2024-04-16 20:57:05 +02:00
parent 9b5f1a36ab
commit 9d3f1541eb
11 changed files with 84 additions and 81 deletions

View File

@@ -15,13 +15,17 @@ export class Subscription {
public async newSubscribtion(
tenantId: number,
planSlug: string,
invoiceInterval: string,
invoicePeriod: number,
subscriptionSlug: string = 'main'
) {
const tenant = await Tenant.query().findById(tenantId).throwIfNotFound();
const plan = await Plan.query().findOne('slug', planSlug).throwIfNotFound();
const isFree = plan.price === 0;
// Take the invoice interval and period from the given plan.
const invoiceInterval = plan.invoiceInternal;
const invoicePeriod = isFree ? Infinity : plan.invoicePeriod;
const subscription = await tenant
.$relatedQuery('subscriptions')
.modify('subscriptionBySlug', subscriptionSlug)