feat(carbet): add lastBookedAt and endpoint
This commit is contained in:
parent
8d36f7008f
commit
fcc2749d1d
5 changed files with 63 additions and 2 deletions
24
src/lib/carbet-last-booked.ts
Normal file
24
src/lib/carbet-last-booked.ts
Normal 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,
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue