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:
jtricerolph 2026-07-04 11:13:33 +00:00
parent 00e5e684fa
commit 663ef5d107
2 changed files with 23 additions and 7 deletions

View file

@ -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,
}
}
}