This commit is contained in:
daniel31x13
2024-11-12 16:17:38 -05:00
parent a4c83dc82f
commit ceed23ff51
3 changed files with 30 additions and 21 deletions
+13 -1
View File
@@ -7,6 +7,11 @@ type Data = {
quantity: number;
periodStart: number;
periodEnd: number;
action:
| "customer.subscription.created"
| "customer.subscription.updated"
| "customer.subscription.deleted"
| "customer.subscription.cancelled";
};
export default async function handleSubscription({
@@ -15,6 +20,7 @@ export default async function handleSubscription({
quantity,
periodStart,
periodEnd,
action,
}: Data) {
const subscription = await prisma.subscription.findUnique({
where: {
@@ -57,7 +63,13 @@ export default async function handleSubscription({
},
});
if (!user) throw new Error("User not found");
if (!user) {
if (action === "customer.subscription.deleted") {
return "User not found or deleted";
} else {
throw new Error("User not found");
}
}
const userId = user.id;