Remove dumb code placement (#5494)
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, #5254 return if no subscription is created so the sub can never be created at all This PR fixes that
This commit is contained in:
@ -96,6 +96,12 @@ export class BillingService {
|
|||||||
return notCanceledSubscriptions?.[0];
|
return notCanceledSubscriptions?.[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBillingSubscription(stripeSubscriptionId: string) {
|
||||||
|
return this.billingSubscriptionRepository.findOneOrFail({
|
||||||
|
where: { stripeSubscriptionId },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getStripeCustomerId(workspaceId: string) {
|
async getStripeCustomerId(workspaceId: string) {
|
||||||
const subscriptions = await this.billingSubscriptionRepository.find({
|
const subscriptions = await this.billingSubscriptionRepository.find({
|
||||||
where: { workspaceId },
|
where: { workspaceId },
|
||||||
@ -265,14 +271,6 @@ export class BillingService {
|
|||||||
subscriptionStatus: data.object.status,
|
subscriptionStatus: data.object.status,
|
||||||
});
|
});
|
||||||
|
|
||||||
const billingSubscription = await this.getCurrentBillingSubscription({
|
|
||||||
workspaceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!billingSubscription) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.billingSubscriptionRepository.upsert(
|
await this.billingSubscriptionRepository.upsert(
|
||||||
{
|
{
|
||||||
workspaceId: workspaceId,
|
workspaceId: workspaceId,
|
||||||
@ -287,6 +285,10 @@ export class BillingService {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const billingSubscription = await this.getBillingSubscription(
|
||||||
|
data.object.id,
|
||||||
|
);
|
||||||
|
|
||||||
await this.billingSubscriptionItemRepository.upsert(
|
await this.billingSubscriptionItemRepository.upsert(
|
||||||
data.object.items.data.map((item) => {
|
data.object.items.data.map((item) => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user