mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: set servers quantity in 0 when the subscription is created
This commit is contained in:
@@ -80,27 +80,17 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
case "customer.subscription.created": {
|
case "customer.subscription.created": {
|
||||||
const newSubscription = event.data.object as Stripe.Subscription;
|
const newSubscription = event.data.object as Stripe.Subscription;
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(admins)
|
.update(admins)
|
||||||
.set({
|
.set({
|
||||||
stripeSubscriptionId: newSubscription.id,
|
stripeSubscriptionId: newSubscription.id,
|
||||||
serversQuantity: newSubscription?.items?.data?.[0]?.quantity ?? 0,
|
serversQuantity: 0,
|
||||||
stripeCustomerId: newSubscription.customer as string,
|
stripeCustomerId: newSubscription.customer as string,
|
||||||
})
|
})
|
||||||
.where(eq(admins.stripeCustomerId, newSubscription.customer as string))
|
.where(eq(admins.stripeCustomerId, newSubscription.customer as string))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
const admin = await findAdminByStripeCustomerId(
|
|
||||||
newSubscription.customer as string,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!admin) {
|
|
||||||
return res.status(400).send("Webhook Error: Admin not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
const newServersQuantity = admin.serversQuantity;
|
|
||||||
await updateServersBasedOnQuantity(admin.adminId, newServersQuantity);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user