From 663ef5d107db14b8154af70ed4be07701d4cc399 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Sat, 4 Jul 2026 11:13:33 +0000 Subject: [PATCH] Room planner: flexible category field resolution + debug logging Resolve NewBook category fields from site_category_id, category_id, or category.id (whichever is present) so categories work regardless of which naming convention the NewBook region uses. Log the first site's keys on each /api/rooms request to confirm field names in docker compose logs. Co-Authored-By: Claude Sonnet 4.6 --- backend/src/lib/booking-flow.js | 12 +++++++++--- backend/src/routes/rooms.js | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/backend/src/lib/booking-flow.js b/backend/src/lib/booking-flow.js index ea139cf..153a64b 100644 --- a/backend/src/lib/booking-flow.js +++ b/backend/src/lib/booking-flow.js @@ -95,13 +95,19 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow) { const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null const departureDate = primaryBooking ? toDateStr(primaryBooking.booking_departure) : null + // NewBook may return category info as flat fields (site_category_id, category_id) + // or as a nested object. Resolve whichever is present. + const catId = site.site_category_id ?? site.category_id ?? site.category?.id ?? null + const catName = site.site_category_name ?? site.category_name ?? site.category?.name ?? '' + const catOrd = site.site_category_order ?? site.category_order ?? site.category?.order ?? 0 + return { site_id: siteId, site_name: site.site_name, site_status: site.site_status || 'unknown', - category_id: String(site.site_category_id || ''), - category_name: site.site_category_name || '', - category_order: site.site_category_order ?? 0, + category_id: catId != null ? String(catId) : '', + category_name: catName, + category_order: catOrd, site_order: site.site_order ?? 0, flow_type: flowType, diff --git a/backend/src/routes/rooms.js b/backend/src/routes/rooms.js index 1443a0e..50a0944 100644 --- a/backend/src/routes/rooms.js +++ b/backend/src/routes/rooms.js @@ -83,15 +83,25 @@ export async function roomRoutes(app) { return reply.status(502).send({ error: `NewBook fetch failed: ${err.message}` }) } - // Derive category map from sites — NewBook includes site_category_id/name/order per site + // Derive category map from sites. Log first site keys to help diagnose field names. + if (sites.length > 0) { + const sample = sites[0] + console.log('[rooms] sample site keys:', Object.keys(sample)) + console.log('[rooms] sample site_category_id:', sample.site_category_id, + '| category_id:', sample.category_id, + '| category:', JSON.stringify(sample.category)) + } + const categoryMap = {} for (const site of sites) { - const catId = String(site.site_category_id || '') + const catId = String( + site.site_category_id ?? site.category_id ?? site.category?.id ?? '' + ) if (catId && !categoryMap[catId]) { categoryMap[catId] = { id: catId, - name: site.site_category_name || catId, - order: site.site_category_order ?? 999, + name: site.site_category_name ?? site.category_name ?? site.category?.name ?? catId, + order: site.site_category_order ?? site.category_order ?? site.category?.order ?? 999, } } }