mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
extract getServerSideBooking
This commit is contained in:
25
lib/getServerSideProps.ts
Normal file
25
lib/getServerSideProps.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import { getBookingByUUID } from '../db/index'
|
||||
|
||||
export const getServerSideBooking: GetServerSideProps = async (context) => {
|
||||
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: {} }
|
||||
}
|
||||
|
||||
await booking.populate('booker').execPopulate()
|
||||
|
||||
// TODO: hack, not sure why _id is not serilizable
|
||||
const bookingJSON = JSON.parse(JSON.stringify(booking.toJSON()))
|
||||
return {
|
||||
props: { booking: bookingJSON },
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user