mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
extract getServerSideBooking
This commit is contained in:
@@ -1,34 +1,13 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import Footer from '../../../components/footer'
|
||||
import Header from '../../../components/header'
|
||||
import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
||||
import { BookingDocument } from '../../../db/booking'
|
||||
import { BOOKING_STATUS } from '../../../db/enums'
|
||||
import { getBookingByUUID } from '../../../db/index'
|
||||
import { dateFormatFrontend } from '../../../helpers/date'
|
||||
import { getBookingStatus } from '../../../helpers/booking'
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const {
|
||||
res,
|
||||
params: { uuid: uuids },
|
||||
} = context
|
||||
const uuid = Array.isArray(uuids) ? uuids[0] : uuids
|
||||
const booking = await getBookingByUUID(uuid)
|
||||
await booking.populate('booker').execPopulate()
|
||||
|
||||
if (!booking) {
|
||||
res.statusCode = 404
|
||||
res.end()
|
||||
return { props: {} }
|
||||
}
|
||||
|
||||
// TODO: hack, not sure why _id is not serilizable
|
||||
const bookingJSON = JSON.parse(JSON.stringify(booking.toJSON()))
|
||||
return {
|
||||
props: { booking: bookingJSON },
|
||||
}
|
||||
}
|
||||
export const getServerSideProps = getServerSideBooking
|
||||
|
||||
async function cancelBooking(booking: BookingDocument) {
|
||||
const response = await fetch(`/api/booking/${booking.uuid}`, {
|
||||
|
||||
Reference in New Issue
Block a user