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 <noreply@anthropic.com>
This commit is contained in:
parent
00e5e684fa
commit
663ef5d107
2 changed files with 23 additions and 7 deletions
|
|
@ -95,13 +95,19 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow) {
|
||||||
const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null
|
const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null
|
||||||
const departureDate = primaryBooking ? toDateStr(primaryBooking.booking_departure) : 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 {
|
return {
|
||||||
site_id: siteId,
|
site_id: siteId,
|
||||||
site_name: site.site_name,
|
site_name: site.site_name,
|
||||||
site_status: site.site_status || 'unknown',
|
site_status: site.site_status || 'unknown',
|
||||||
category_id: String(site.site_category_id || ''),
|
category_id: catId != null ? String(catId) : '',
|
||||||
category_name: site.site_category_name || '',
|
category_name: catName,
|
||||||
category_order: site.site_category_order ?? 0,
|
category_order: catOrd,
|
||||||
site_order: site.site_order ?? 0,
|
site_order: site.site_order ?? 0,
|
||||||
|
|
||||||
flow_type: flowType,
|
flow_type: flowType,
|
||||||
|
|
|
||||||
|
|
@ -83,15 +83,25 @@ export async function roomRoutes(app) {
|
||||||
return reply.status(502).send({ error: `NewBook fetch failed: ${err.message}` })
|
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 = {}
|
const categoryMap = {}
|
||||||
for (const site of sites) {
|
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]) {
|
if (catId && !categoryMap[catId]) {
|
||||||
categoryMap[catId] = {
|
categoryMap[catId] = {
|
||||||
id: catId,
|
id: catId,
|
||||||
name: site.site_category_name || catId,
|
name: site.site_category_name ?? site.category_name ?? site.category?.name ?? catId,
|
||||||
order: site.site_category_order ?? 999,
|
order: site.site_category_order ?? site.category_order ?? site.category?.order ?? 999,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue