mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
51 lines
963 B
TypeScript
51 lines
963 B
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)
|
|
|
|
if (!booking) {
|
|
res.statusCode = 404
|
|
res.end()
|
|
return { props: { booking: null } }
|
|
}
|
|
|
|
return {
|
|
props: { booking },
|
|
}
|
|
}
|