mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix tz issue when booking in non-utc time
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
import { BookFormData } from '../context/book'
|
||||
import { BOOKING_STATUS } from '../db/enums'
|
||||
import { dateFormatBackend } from './date';
|
||||
import fetch from './fetch'
|
||||
|
||||
function getBody(formData: BookFormData) {
|
||||
const body: any = {
|
||||
...formData,
|
||||
};
|
||||
|
||||
// if existend, convert dates to TZ less YYYY-MM-DD format
|
||||
body.startDate && (body.startDate = dateFormatBackend(body.startDate))
|
||||
body.endDate && (body.endDate = dateFormatBackend(body.endDate))
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
export function getBookingStatus(status: BOOKING_STATUS) {
|
||||
switch (status) {
|
||||
case BOOKING_STATUS.REQUESTED:
|
||||
@@ -16,10 +30,10 @@ export function getBookingStatus(status: BOOKING_STATUS) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function createBooking(formData: object) {
|
||||
export async function createBooking(formData: BookFormData) {
|
||||
return fetch('/api/bookings', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
body: getBody(formData),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,9 +44,9 @@ export async function cancelBooking(uuid: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function patchBooking(uuid: string, bookingData: object) {
|
||||
export async function patchBooking(uuid: string, bookingData: BookFormData) {
|
||||
return fetch(`/api/bookings/${uuid}`, {
|
||||
method: 'PATCH',
|
||||
body: { ...bookingData },
|
||||
body: getBody(bookingData),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user