mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
move CRUD operations to helpers
This commit is contained in:
@@ -5,25 +5,10 @@ import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
||||
import { Booking } from '../../../db/booking'
|
||||
import { BOOKING_STATUS } from '../../../db/enums'
|
||||
import { daysFormatFrontend } from '../../../helpers/date'
|
||||
import { getBookingStatus } from '../../../helpers/booking'
|
||||
import { getBookingStatus, cancelBooking } from '../../../helpers/booking'
|
||||
|
||||
export const getServerSideProps = getServerSideBooking
|
||||
|
||||
async function cancelBooking(booking: Booking) {
|
||||
const response = await fetch(`/api/booking/${booking.uuid}`, {
|
||||
method: 'PATCH',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
referrerPolicy: 'no-referrer',
|
||||
body: JSON.stringify({ status: BOOKING_STATUS.CANCELED }),
|
||||
})
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export default function ShowBooking({
|
||||
booking: bookingProp,
|
||||
}: {
|
||||
@@ -44,7 +29,7 @@ export default function ShowBooking({
|
||||
try {
|
||||
setStoringBookingError(null)
|
||||
setStoringBooking(true)
|
||||
const updatedBooking = await cancelBooking(booking)
|
||||
const updatedBooking = await cancelBooking(booking.uuid)
|
||||
setBooking(updatedBooking)
|
||||
} catch (error) {
|
||||
setStoringBookingError(
|
||||
|
||||
Reference in New Issue
Block a user