Skip to content

Commit

Permalink
Remove dumb code placement (twentyhq#5494)
Browse files Browse the repository at this point in the history
Fix a bug introduced in [this
PR](https://github.com/twentyhq/twenty/pull/5254/files)

When a subscription is created, we need to create the subscription,
twentyhq#5254 return if no subscription is created so the sub can never be
created at all

This PR fixes that
  • Loading branch information
martmull authored May 21, 2024
1 parent 4fcdfbf commit ec248f8
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class BillingService {
return notCanceledSubscriptions?.[0];
}

async getBillingSubscription(stripeSubscriptionId: string) {
return this.billingSubscriptionRepository.findOneOrFail({
where: { stripeSubscriptionId },
});
}

async getStripeCustomerId(workspaceId: string) {
const subscriptions = await this.billingSubscriptionRepository.find({
where: { workspaceId },
Expand Down Expand Up @@ -265,14 +271,6 @@ export class BillingService {
subscriptionStatus: data.object.status,
});

const billingSubscription = await this.getCurrentBillingSubscription({
workspaceId,
});

if (!billingSubscription) {
return;
}

await this.billingSubscriptionRepository.upsert(
{
workspaceId: workspaceId,
Expand All @@ -287,6 +285,10 @@ export class BillingService {
},
);

const billingSubscription = await this.getBillingSubscription(
data.object.id,
);

await this.billingSubscriptionItemRepository.upsert(
data.object.items.data.map((item) => {
return {
Expand Down

0 comments on commit ec248f8

Please sign in to comment.