diff --git a/backend/handlers/bookings/bookings.go b/backend/handlers/bookings/bookings.go
index 8d505ee..41b288b 100644
--- a/backend/handlers/bookings/bookings.go
+++ b/backend/handlers/bookings/bookings.go
@@ -453,7 +453,7 @@ func GetAllAdminBookingsHandler(w http.ResponseWriter, r *http.Request) {
}
// Add ordering and pagination (NO GROUP BY needed here)
- baseQuery += " ORDER BY b.start_time ASC"
+ baseQuery += " ORDER BY b.start_time DESC"
if req.PerPage > 0 {
baseQuery += fmt.Sprintf(" LIMIT $%d OFFSET $%d", paramCount, paramCount+1)
args = append(args, req.PerPage, (req.Page-1)*req.PerPage)
@@ -954,7 +954,7 @@ func SearchAdminBookingsHandler(w http.ResponseWriter, r *http.Request) {
JOIN services s ON bs.service_id = s.id
WHERE bs.booking_id = b.id AND s.name ILIKE $1 ESCAPE '\'
)
- ORDER BY b.start_time ASC
+ ORDER BY b.start_time DESC
LIMIT $2 OFFSET $3
`
diff --git a/frontend/src/lib/components/admin/BookingsCard.svelte b/frontend/src/lib/components/admin/BookingsCard.svelte
index 845c2bf..70ffb32 100644
--- a/frontend/src/lib/components/admin/BookingsCard.svelte
+++ b/frontend/src/lib/components/admin/BookingsCard.svelte
@@ -136,43 +136,40 @@
const response = await fetch(
`/api/admin/bookings/search?q=${encodeURIComponent(bookingQuery)}`,
{
- method: 'GET',
headers: {
- 'Content-Type': 'application/json',
Authorization: `Bearer ${authStore.currentToken}`
}
}
);
- if (response.ok) {
- const data = await response.json();
- bookings = data.bookings.map((b: any) => ({
- id: b.id,
- start_time: b.start_time,
- status: b.status,
- notes: b.notes,
- created_at: b.created_at,
- updated_at: b.updated_at,
- created_by: b.created_by,
- user: b.user
- ? {
- id: b.user.id,
- full_name: b.user.full_name
- }
- : undefined,
- services: b.services || [],
- total_amount: b.total_amount || 0,
- amount_paid: b.amount_paid || 0,
- amount_due: b.amount_due || 0,
- duration_minutes: b.duration_minutes || 0
- }));
- } else {
- const text = await response.text();
- toast.error('Failed to search bookings: ' + text);
+ // HTTP error (400 / 401 / 500 etc)
+ if (!response.ok) {
+ const message = await response.text();
+ throw new Error(message || `Request failed (${response.status})`);
}
+
+ const data = await response.json();
+ const bookingsData = Array.isArray(data.bookings) ? data.bookings : [];
+
+ bookings = bookingsData.map((b: any) => ({
+ id: b.id,
+ start_time: b.start_time,
+ status: b.status,
+ notes: b.notes,
+ created_at: b.created_at,
+ updated_at: b.updated_at,
+ created_by: b.created_by,
+ user: b.user ? { id: b.user.id, full_name: b.user.full_name } : undefined,
+ services: b.services || [],
+ total_amount: b.total_amount || 0,
+ amount_paid: b.amount_paid || 0,
+ amount_due: b.amount_due || 0,
+ duration_minutes: b.duration_minutes || 0
+ }));
} catch (err) {
- console.error('Error searching bookings:', err);
- toast.error('Network error searching bookings');
+ console.error('Search bookings failed:', err);
+
+ toast.error(err instanceof Error ? err.message : 'Unexpected error searching bookings');
} finally {
loadingSearch = false;
}
@@ -297,9 +294,6 @@