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) if (!booking) { res.statusCode = 404 res.end() return { props: { booking: null } } } return { props: { booking }, } }