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

@ -0,0 +1,24 @@
import { BookingStatus } from "@/generated/prisma/enums";
import { prisma } from "@/lib/prisma";
export async function refreshCarbetLastBookedAt(carbetId: string): Promise<void> {
const latestConfirmedBooking = await prisma.booking.findFirst({
where: {
carbetId,
status: BookingStatus.CONFIRMED,
},
orderBy: {
updatedAt: "desc",
},
select: {
updatedAt: true,
},
});
await prisma.carbet.update({
where: { id: carbetId },
data: {
lastBookedAt: latestConfirmedBooking?.updatedAt ?? null,
},
});
}