mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
move CRUD operations to helpers
This commit is contained in:
@@ -3,12 +3,11 @@ import Footer from '../../../../components/footer'
|
||||
import Header from '../../../../components/header'
|
||||
import Input from '../../../../components/input'
|
||||
import Select from '../../../../components/select'
|
||||
import { AdditionalCost, Bill } from '../../../../db/bill'
|
||||
import { Booking } from '../../../../db/booking'
|
||||
import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums'
|
||||
import { getMilageMax } from '../../../../db/index'
|
||||
import { daysFormatFrontend } from '../../../../helpers/date'
|
||||
import { getBillTotal } from '../../../../helpers/bill'
|
||||
import { getBillTotal, createBill, patchBill } from '../../../../helpers/bill'
|
||||
import { getBookingStatus } from '../../../../helpers/booking'
|
||||
import withSession, {
|
||||
isAdminSession,
|
||||
@@ -79,31 +78,6 @@ function getBillStatusLabel(status: BILL_STATUS) {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveBill(
|
||||
booking: Booking,
|
||||
bill: {
|
||||
milageStart: number
|
||||
milageEnd: number
|
||||
milage?: number
|
||||
tarif: MILAGE_TARIFS
|
||||
additionalCosts: AdditionalCost[]
|
||||
status: BILL_STATUS
|
||||
}
|
||||
): Promise<Bill> {
|
||||
const response = await fetch(`/api/admin/booking/${booking.uuid}/bill`, {
|
||||
method: !!booking.bill ? 'PATCH' : 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
referrerPolicy: 'no-referrer',
|
||||
body: JSON.stringify(bill),
|
||||
})
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export default function BookingBillPage({
|
||||
booking: bookingProp,
|
||||
milageMax,
|
||||
@@ -136,7 +110,8 @@ export default function BookingBillPage({
|
||||
setStoringError(null)
|
||||
|
||||
try {
|
||||
const bill = await saveBill(booking, {
|
||||
const saveBill = !!booking.bill ? createBill : patchBill
|
||||
const bill = await saveBill(booking.uuid, {
|
||||
milageStart,
|
||||
milageEnd,
|
||||
milage,
|
||||
|
||||
@@ -11,7 +11,7 @@ import withSession, {
|
||||
} from '../../../../lib/session'
|
||||
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
|
||||
import { Booking } from '../../../../db/booking'
|
||||
import { getBookingStatus } from '../../../../helpers/booking'
|
||||
import { getBookingStatus, patchBooking } from '../../../../helpers/booking'
|
||||
import { daysFormatFrontend } from '../../../../helpers/date'
|
||||
import { BOOKING_STATUS } from '../../../../db/enums'
|
||||
|
||||
@@ -36,21 +36,6 @@ export const getServerSideProps: GetServerSideProps = withSession(
|
||||
}
|
||||
)
|
||||
|
||||
async function patchBooking(uuid: string, bookingData: any) {
|
||||
const response = await fetch(`/api/admin/booking/${uuid}`, {
|
||||
method: 'PATCH',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
referrerPolicy: 'no-referrer',
|
||||
body: JSON.stringify({ ...bookingData }),
|
||||
})
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export default function ShowBookingAdmin({
|
||||
booking: bookingProp,
|
||||
}: {
|
||||
|
||||
Reference in New Issue
Block a user