36 lines
947 B
TypeScript
36 lines
947 B
TypeScript
import { Booking, Prisma, PublicUser, Station } from "@repo/db";
|
|
import axios from "axios";
|
|
|
|
export const getBookingsAPI = async (filter: Prisma.BookingWhereInput) => {
|
|
const res = await axios.get<
|
|
(Booking & {
|
|
Station: Station;
|
|
User: PublicUser;
|
|
})[]
|
|
>("/api/bookings", {
|
|
params: {
|
|
filter: JSON.stringify(filter),
|
|
},
|
|
});
|
|
if (res.status !== 200) {
|
|
throw new Error("Failed to fetch stations");
|
|
}
|
|
return res.data;
|
|
};
|
|
|
|
export const createBookingAPI = async (booking: Prisma.BookingCreateInput) => {
|
|
const response = await axios.post("/api/bookings", booking);
|
|
if (response.status !== 201) {
|
|
throw new Error("Failed to create booking");
|
|
}
|
|
return response.data;
|
|
};
|
|
|
|
export const deleteBookingAPI = async (bookingId: string) => {
|
|
const response = await axios.delete(`/api/bookings/${bookingId}`);
|
|
if (!response.status.toString().startsWith("2")) {
|
|
throw new Error("Failed to delete booking");
|
|
}
|
|
return bookingId;
|
|
};
|