mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 22:47:15 +01:00
57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
import { Booking } from '@prisma/client';
|
|
import { startOfYear } from 'date-fns'
|
|
import { nowInTz } from '../helpers/date'
|
|
import { getBookingByUUID, getBookings } from '../db/index'
|
|
|
|
export type ServerSideBooking = {
|
|
props: {
|
|
booking: Booking
|
|
}
|
|
}
|
|
|
|
export type ServerSideRecentBooking = {
|
|
props: {
|
|
bookings: Booking[]
|
|
}
|
|
}
|
|
|
|
export const getServerSideRecentBookings =
|
|
async () => {
|
|
const bookings = await getBookings({
|
|
startDateGreaterThan: startOfYear(nowInTz()).toISOString(),
|
|
})
|
|
|
|
return {
|
|
props: {
|
|
bookings: bookings,
|
|
},
|
|
}
|
|
}
|
|
|
|
export const getServerSideBooking = async (
|
|
context: any
|
|
) => {
|
|
const {
|
|
res,
|
|
params: { uuid: uuids },
|
|
} = context
|
|
const uuid = Array.isArray(uuids) ? uuids[0] : uuids
|
|
const booking = await getBookingByUUID(uuid)
|
|
|
|
console.log(booking.createdAt);
|
|
|
|
if (!booking) {
|
|
res.statusCode = 404
|
|
res.end()
|
|
return { props: { booking: null } }
|
|
}
|
|
|
|
return {
|
|
props: { booking: {
|
|
...booking,
|
|
createdAt: booking.createdAt.toISOString(),
|
|
updatedAt: booking.updatedAt.toISOString(),
|
|
}},
|
|
}
|
|
}
|