Add Prettier support.

This commit is contained in:
2024-08-12 20:59:51 +02:00
parent d4458e8f00
commit b034d2e9c9
62 changed files with 1380 additions and 1105 deletions
+16 -14
View File
@@ -2,18 +2,20 @@ import { NewBooking, NewBookingResponse } from "@/model/Bookings";
import { fetcherWithFilter } from "./backend";
export async function APISendCreateBooking(bookingData: NewBooking | null) {
if (!bookingData) {
return {
bookingResponse: null,
isError: true
}
}
const rs = await fetcherWithFilter<NewBookingResponse>("/api/booking/create", bookingData);
if (!bookingData) {
return {
bookingResponse: rs,
isError: false
}
}
bookingResponse: null,
isError: true,
};
}
const rs = await fetcherWithFilter<NewBookingResponse>(
"/api/booking/create",
bookingData,
);
return {
bookingResponse: rs,
isError: false,
};
}
+12 -9
View File
@@ -1,25 +1,28 @@
import { RoomCategory } from "@/model/RoomCategory";
import { fetcher, fetcherUnwraper } from "./backend";
import useSWR from 'swr';
import useSWR from "swr";
export function useAPIRoomCategories() {
const { data, error, isLoading } = useSWR<RoomCategory[]>('/api/room/category', fetcherUnwraper)
const { data, error, isLoading } = useSWR<RoomCategory[]>(
"/api/room/category",
fetcherUnwraper,
);
return {
roomCategoryList: data,
isLoading,
isError: error
}
isError: error,
};
}
export function useAPIRoomCategoryId(categoryId: number) {
const url = categoryId ? '/api/room/category/' + categoryId : null;
const url = categoryId ? "/api/room/category/" + categoryId : null;
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher)
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher);
return {
roomCategory: data,
isLoading,
isError: error
}
}
isError: error,
};
}
+39 -23
View File
@@ -1,33 +1,49 @@
import { fetcherUnwraperWithFilter } from "./backend";
import useSWR from 'swr';
import { AvailabilityFilter, AvailabilityRequest, FareFilter, FareRequest, RoomAvailabity, RoomPrice } from "@/model/RoomSearch";
import useSWR from "swr";
import {
AvailabilityFilter,
AvailabilityRequest,
FareFilter,
FareRequest,
RoomAvailabity,
RoomPrice,
} from "@/model/RoomSearch";
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
const request: AvailabilityRequest | null = filter
? {
filter: filter,
}
: null;
const request: AvailabilityRequest | null = filter ? {
filter: filter
} : null;
const { data, isLoading, error } = useSWR(
request ? ["/api/search/availability", request] : null,
([url, request]) =>
fetcherUnwraperWithFilter<RoomAvailabity[]>(url, request),
);
const { data, isLoading, error } = useSWR(request ? ['/api/search/availability', request] : null, ([url, request]) => fetcherUnwraperWithFilter<RoomAvailabity[]>(url, request))
return {
roomAvailabilityList: data,
isLoading,
isError: error
}
return {
roomAvailabilityList: data,
isLoading,
isError: error,
};
}
export function useAPIRoomPrices(filter: FareFilter | null) {
const request: FareRequest | null = filter
? {
filter: filter,
}
: null;
const request: FareRequest | null = filter ? {
filter: filter
} : null;
const { data, isLoading, error } = useSWR(
request ? ["/api/search/fares", request] : null,
([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request),
);
const { data, isLoading, error } = useSWR(request ? ['/api/search/fares', request] : null, ([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request))
return {
roomPriceList: data,
isLoading,
isError: error
}
}
return {
roomPriceList: data,
isLoading,
isError: error,
};
}
+58 -53
View File
@@ -1,66 +1,71 @@
const BACKEND_HOST = import.meta.env.VITE_BACKEND_HOST;
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
const url = BACKEND_HOST + (BACKEND_PORT == 443 || BACKEND_PORT == 80 ? "" : ":" + BACKEND_PORT)
const url =
BACKEND_HOST +
(BACKEND_PORT == 443 || BACKEND_PORT == 80 ? "" : ":" + BACKEND_PORT);
export function fetcher<T>(endpoint: string): Promise<T> {
return fetch(url + endpoint, {
method: "GET"
})
.then(r => {
if (!r.ok) {
throw new Error(r.statusText)
}
const data = r.json();
return data as Promise<T>;
})
return fetch(url + endpoint, {
method: "GET",
}).then((r) => {
if (!r.ok) {
throw new Error(r.statusText);
}
const data = r.json();
return data as Promise<T>;
});
}
export function fetcherUnwraper<T>(endpoint: string): Promise<T> {
return fetch(url + endpoint)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json() as Promise<{ results: T }>
})
.then(data => {
return data.results
})
return fetch(url + endpoint)
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<{ results: T }>;
})
.then((data) => {
return data.results;
});
}
export function fetcherWithFilter<T>(endpoint: string, body: NonNullable<unknown>): Promise<T> {
return fetch(url + endpoint, {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
})
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json() as Promise<T>
})
export function fetcherWithFilter<T>(
endpoint: string,
body: NonNullable<unknown>,
): Promise<T> {
return fetch(url + endpoint, {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
}).then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<T>;
});
}
export function fetcherUnwraperWithFilter<T>(endpoint: string, body: NonNullable<unknown>): Promise<T> {
return fetch(url + endpoint, {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
export function fetcherUnwraperWithFilter<T>(
endpoint: string,
body: NonNullable<unknown>,
): Promise<T> {
return fetch(url + endpoint, {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
})
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<{ results: T }>;
})
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json() as Promise<{ results: T }>
})
.then(data => {
return data.results
})
}
.then((data) => {
return data.results;
});
}