diff --git a/backend/src/lib/newbook.js b/backend/src/lib/newbook.js index 7f7cb06..7dabbeb 100644 --- a/backend/src/lib/newbook.js +++ b/backend/src/lib/newbook.js @@ -58,13 +58,14 @@ export async function fetchSites() { return res?.data ?? [] } -// Fetch bookings spanning a date range. -// list_type 'all' includes arrived, confirmed, unconfirmed, departed, blocked. +// Fetch bookings whose stay overlaps the date window. +// list_type 'staying' returns bookings where arrival <= period_to AND departure >= period_from, +// so a booking arriving on period_to is included. This matches the original plugin behaviour. export async function fetchBookings(fromDate, toDate) { const res = await callApi('bookings_list', { period_from: `${fromDate} 00:00:00`, period_to: `${toDate} 23:59:59`, - list_type: 'all', + list_type: 'staying', }) return res?.data ?? [] } diff --git a/backend/src/routes/rooms.js b/backend/src/routes/rooms.js index a2db666..e8efcfc 100644 --- a/backend/src/routes/rooms.js +++ b/backend/src/routes/rooms.js @@ -54,13 +54,12 @@ export async function roomRoutes(app) { const viewDate = req.query.date || new Date().toISOString().slice(0, 10) const roomName = req.query.room - const yesterday = dateOffset(viewDate, -1) - const tomorrow = dateOffset(viewDate, +1) - const dayAfterTomorrow = dateOffset(viewDate, +2) + const yesterday = dateOffset(viewDate, -1) + const tomorrow = dateOffset(viewDate, +1) const [sites, bookings] = await Promise.all([ fetchSites(), - fetchBookings(yesterday, dayAfterTomorrow), + fetchBookings(yesterday, tomorrow), ]) if (!roomName) { @@ -98,7 +97,7 @@ export async function roomRoutes(app) { const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow) return { - view_date: viewDate, yesterday, tomorrow, day_after_tomorrow: dayAfterTomorrow, + view_date: viewDate, yesterday, tomorrow, site: { id: siteId, name: site.site_name, fields: Object.keys(site) }, booking_id_fields: idFields, total_bookings_fetched: bookings.length, @@ -151,12 +150,11 @@ export async function roomRoutes(app) { // Fetch from NewBook in parallel let sites, bookings, tasks try { - // Fetch bookings one day beyond tomorrow so tomorrow-arriving bookings appear - // in nextBooking lookups (some NewBook regions exclude period_to-date arrivals). - const dayAfterTomorrow = dateOffset(viewDate, +2) + // list_type 'staying' includes bookings with arrival <= period_to, + // so fetching yesterday→tomorrow captures all adjacent-day brackets. ;[sites, bookings, tasks] = await Promise.all([ fetchSites(), - fetchBookings(yesterday, dayAfterTomorrow), + fetchBookings(yesterday, tomorrow), fetchTasks(yesterday, tomorrow), ]) } catch (err) {