Fix reservation fetching

This commit is contained in:
Joshua Schmucker 2026-02-05 17:26:22 +01:00
parent ec7f07d788
commit 56204f3324
2 changed files with 22 additions and 6 deletions

View File

@ -243,7 +243,7 @@ const UserDashboard: React.FC = () => {
.sort((a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime()) .sort((a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime())
.map(reservation => ( .map(reservation => (
<div <div
key={reservation.id} key={reservation.referenceNumber}
style={{ style={{
backgroundColor: 'white', backgroundColor: 'white',
padding: '1.5rem', padding: '1.5rem',

View File

@ -123,9 +123,21 @@ export class SimpleLibreBookingClient {
} }
} }
const url = resourceId // Use a wide date range to get all reservations
? `${this.baseUrl}/Services/index.php/Reservations/?resourceId=${resourceId}` const today = new Date();
: `${this.baseUrl}/Services/index.php/Reservations/`; const threeMonthsAgo = new Date(today.getTime() - (90 * 24 * 60 * 60 * 1000));
const threeMonthsFromNow = new Date(today.getTime() + (90 * 24 * 60 * 60 * 1000));
const params = new URLSearchParams({
startDateTime: threeMonthsAgo.toISOString().split('.')[0] + 'Z',
endDateTime: threeMonthsFromNow.toISOString().split('.')[0] + 'Z',
});
if (resourceId) {
params.append('resourceId', resourceId);
}
const url = `${this.baseUrl}/Services/index.php/Reservations/?${params.toString()}`;
const headers: Record<string, string> = { const headers: Record<string, string> = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -145,7 +157,11 @@ export class SimpleLibreBookingClient {
} }
const data = await response.json(); const data = await response.json();
console.log('Reservations response:', data); console.log('API date range:', {
start: data.startDateTime,
end: data.endDateTime
});
console.log('Found reservations:', data.reservations.length);
return data.reservations || []; return data.reservations || [];
} }