feat(carbet): add lastBookedAt and endpoint

This commit is contained in:
Karbé Architect 2026-05-30 17:52:41 +00:00
parent 8d36f7008f
commit fcc2749d1d
5 changed files with 63 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import {
PaymentStatus,
SubscriptionStatus,
} from "@/generated/prisma/enums";
import { refreshCarbetLastBookedAt } from "@/lib/carbet-last-booked";
import { prisma } from "@/lib/prisma";
import { fromStripeTimestamp, getStripeClient } from "@/lib/stripe";
@ -36,13 +37,17 @@ async function handleCheckoutCompleted(session: Stripe.Checkout.Session) {
const type = session.metadata?.type;
if (type === "booking" && bookingId) {
await prisma.booking.update({
const booking = await prisma.booking.update({
where: { id: bookingId },
data: {
paymentStatus: PaymentStatus.SUCCEEDED,
status: BookingStatus.CONFIRMED,
},
select: {
carbetId: true,
},
});
await refreshCarbetLastBookedAt(booking.carbetId);
return;
}
@ -78,13 +83,17 @@ async function handlePaymentIntentFailed(paymentIntent: Stripe.PaymentIntent) {
return;
}
await prisma.booking.update({
const booking = await prisma.booking.update({
where: { id: bookingId },
data: {
paymentStatus: PaymentStatus.FAILED,
status: BookingStatus.CANCELLED,
},
select: {
carbetId: true,
},
});
await refreshCarbetLastBookedAt(booking.carbetId);
}
async function handleSubscriptionUpdated(subscription: Stripe.Subscription) {