mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
fix tz issue when booking in non-utc time
This commit is contained in:
@@ -16,10 +16,12 @@ export type Booking = {
|
|||||||
zip: string
|
zip: string
|
||||||
city: string
|
city: string
|
||||||
bill?: Bill
|
bill?: Bill
|
||||||
start: string
|
// format YYYY-MM-DD
|
||||||
|
start: string,
|
||||||
startDate: Date
|
startDate: Date
|
||||||
endDate: Date
|
// format YYYY-MM-DD
|
||||||
end: string
|
end: string
|
||||||
|
endDate: Date
|
||||||
status?: BOOKING_STATUS
|
status?: BOOKING_STATUS
|
||||||
purpose?: string
|
purpose?: string
|
||||||
org?: string
|
org?: string
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
|
import { BookFormData } from '../context/book'
|
||||||
import { BOOKING_STATUS } from '../db/enums'
|
import { BOOKING_STATUS } from '../db/enums'
|
||||||
|
import { dateFormatBackend } from './date';
|
||||||
import fetch from './fetch'
|
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) {
|
export function getBookingStatus(status: BOOKING_STATUS) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case BOOKING_STATUS.REQUESTED:
|
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', {
|
return fetch('/api/bookings', {
|
||||||
method: 'POST',
|
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}`, {
|
return fetch(`/api/bookings/${uuid}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: { ...bookingData },
|
body: getBody(bookingData),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user