Buchungssystem erste überarbeitungen
This commit is contained in:
35
apps/hub/app/(app)/_querys/bookings.ts
Normal file
35
apps/hub/app/(app)/_querys/bookings.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user