mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 14:37:13 +01:00
34 lines
767 B
TypeScript
34 lines
767 B
TypeScript
import { getBookingByUUID } from '../db/index'
|
|
|
|
export interface ServerSideBooking {
|
|
props: {
|
|
booking: object
|
|
}
|
|
}
|
|
|
|
export const getServerSideBooking = async (
|
|
context: any
|
|
): Promise<ServerSideBooking> => {
|
|
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 } }
|
|
}
|
|
|
|
await booking.populate('booker').execPopulate()
|
|
await booking.populate('bill').execPopulate()
|
|
|
|
// TODO: hack, not sure why _id is not serilizable
|
|
const bookingJSON = JSON.parse(JSON.stringify(booking.toJSON())) as object
|
|
return {
|
|
props: { booking: bookingJSON },
|
|
}
|
|
}
|