bug fix for atemschutz
This commit is contained in:
117
frontend/src/services/bookings.ts
Normal file
117
frontend/src/services/bookings.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { api } from './api';
|
||||
import type {
|
||||
FahrzeugBuchungListItem,
|
||||
FahrzeugBuchung,
|
||||
Fahrzeug,
|
||||
CreateBuchungInput,
|
||||
} from '../types/booking.types';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Response shapes from the backend
|
||||
// ---------------------------------------------------------------------------
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data: T;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Booking API service
|
||||
// ---------------------------------------------------------------------------
|
||||
export const bookingApi = {
|
||||
// -------------------------------------------------------------------------
|
||||
// Calendar / listing
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
getCalendarRange(from: Date, to: Date, fahrzeugId?: string): Promise<FahrzeugBuchungListItem[]> {
|
||||
return api
|
||||
.get<ApiResponse<FahrzeugBuchungListItem[]>>('/api/bookings/calendar', {
|
||||
params: {
|
||||
from: from.toISOString(),
|
||||
to: to.toISOString(),
|
||||
...(fahrzeugId ? { fahrzeugId } : {}),
|
||||
},
|
||||
})
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
getUpcoming(limit = 20): Promise<FahrzeugBuchungListItem[]> {
|
||||
return api
|
||||
.get<ApiResponse<FahrzeugBuchungListItem[]>>('/api/bookings/upcoming', {
|
||||
params: { limit },
|
||||
})
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Availability check
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
checkAvailability(
|
||||
fahrzeugId: string,
|
||||
from: Date,
|
||||
to: Date
|
||||
): Promise<{ available: boolean }> {
|
||||
return api
|
||||
.get<ApiResponse<{ available: boolean }>>('/api/bookings/availability', {
|
||||
params: {
|
||||
fahrzeugId,
|
||||
from: from.toISOString(),
|
||||
to: to.toISOString(),
|
||||
},
|
||||
})
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Single booking
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
getById(id: string): Promise<FahrzeugBuchung> {
|
||||
return api
|
||||
.get<ApiResponse<FahrzeugBuchung>>(`/api/bookings/${id}`)
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// CRUD
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
create(data: CreateBuchungInput): Promise<FahrzeugBuchung> {
|
||||
return api
|
||||
.post<ApiResponse<FahrzeugBuchung>>('/api/bookings', data)
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
update(id: string, data: Partial<CreateBuchungInput>): Promise<FahrzeugBuchung> {
|
||||
return api
|
||||
.patch<ApiResponse<FahrzeugBuchung>>(`/api/bookings/${id}`, data)
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
|
||||
cancel(id: string, abgesagt_grund: string): Promise<void> {
|
||||
return api
|
||||
.delete(`/api/bookings/${id}`, { data: { abgesagt_grund } })
|
||||
.then(() => undefined);
|
||||
},
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// iCal
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
getCalendarToken(): Promise<{ token: string; subscribeUrl: string }> {
|
||||
return api
|
||||
.get<ApiResponse<{ token: string; subscribeUrl: string }>>(
|
||||
'/api/bookings/calendar-token'
|
||||
)
|
||||
.then((r) => r.data.data);
|
||||
},
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Vehicle helper (shared with booking page)
|
||||
// ---------------------------------------------------------------------------
|
||||
export function fetchVehicles(): Promise<Fahrzeug[]> {
|
||||
return api
|
||||
.get<ApiResponse<Fahrzeug[]>>('/api/vehicles')
|
||||
.then((r) => r.data.data.filter((v: Fahrzeug) => !v.archived_at));
|
||||
}
|
||||
Reference in New Issue
Block a user