Refactoring Property Constants and Adding a “Hosts by Location” Module to the Hotel‑IT Ops Dashboard
TL;DR: I cleaned up the property constants, removed obsolete entries, and introduced a new “Hosts / Collaborators” widget that pulls data per location independent of Nuvola. The changes touch lib/properties.js, the UI markup, the client‑side dashboard logic, and the API data contract, resulting in a more maintainable code base and a functional host view.
The Problem
The dashboard displayed three stale property identifiers (CUNRI, MIDRI) that no longer existed in the backend. Their presence caused two issues:
- Broken look‑ups – When the UI tried to resolve
CUNRIorMIDRIviaPROPERTIESit receivedundefined, leading toTypeError: Cannot read property 'name' of undefinedin several rendering functions. - Missing host information – The “Colaboradores / Anfitriones” view was hard‑wired to Nuvola’s data model, which meant we could not display hosts per location for properties that are not managed by Nuvola (e.g., new boutique hotels).
Both problems manifested as empty sections on the dashboard and console errors that confused developers during debugging.
What I Tried First
My first attempt was to patch the UI at runtime: I added a guard in public/js/app.js that defaulted missing property names to "Unknown". While this prevented the crash, it masked the root cause and left the stale identifiers in the source, which would reappear if another developer added a new property later.
I also tried to reuse the existing Nuvola endpoint for hosts, adding a query parameter to filter by location. The endpoint rejected the filter because its schema is tied to Nuvola’s internal IDs, not the property codes we use on the front‑end. The request returned 400 Bad Request with the message Invalid location filter.
Both work‑arounds were short‑term fixes and added technical debt. I needed a proper refactor.
The Implementation
1. Clean up lib/properties.js
Removed the obsolete entries and renamed CUNRP to the correct display name.
--- a/lib/properties.js +++ b/lib/properties.js @@ -5,12 +5,10 @@ export const PROPERTIES = { HRSJD: "Hard Rock Hotel SJD", NHSJD: "Nobu Hotel Los Cabos", BKCUN: "Bonampak Cancun", - CUNRI: "Residence Inn Cancun", - CUNRP: "Residence Inn + CUNRP: "Residence INN Collection", // MIDRI entry removed completely }; Why this matters: The PROPERTIES constant is the single source of truth for all UI look‑ups. Removing dead keys eliminates undefined look‑ups and reduces bundle size.
2. Extend the API contract for infrastructure locations
Added a new list identifier __infLocs to the generic LISTS map in api/data/[action].js. This tells the back‑end to include the new “infra” fields for every property.
--- a/api/data/[action].js +++ b/api/data/[action].js @@ -18,6 +18,7 @@ const LISTS = { __sdOps: ["name", "prev", "in", "out"], __invLocs: ["name", "srv", "comp", "mob", "tab"], __vulnLocs: ["name", "cur", "prev"], + __infLocs: ["name", "srv", "lan", "wifi", "isp"], }; Why this matters: The front‑end now receives a consistent payload (infLocs) for any property, allowing the new host widget to compute availability without hard‑coding field names.
3. Add markup for the Hosts widget
Inserted a new container in public/index.html right after the infrastructure section.
--- a/public/index.html +++ b/public/index.html @@ -327,6 +327,21 @@ .d2 { display:flex; flex-direction:column; gap:12px; padding:14px 16px; background:#fff; } .d2-row { display:flex; gap:12px; align-items:stretch; } +.d2-col { display:flex; flex-direction:column; gap:8px; } +.hosts-widget { + background:#f9fafb; + border:1px solid #e2e8f0; + border-radius:6px; + padding:12px; +} +.hosts-widget h4 { + margin:0 0 8px; + font-size:16px; + color:#2d3748; +} +.hosts-widget ul { list-style:none; margin:0; padding:0; } +.hosts-widget li { margin-bottom:4px; } The new CSS classes (.d2-col, .hosts-widget) keep the UI consistent with existing components.
4. Implement renderHosts() in public/js/app.js
Added a dedicated function that pulls host data from the API (/api/data/hosts) and renders it per location.
--- a/public/js/app.js +++ b/public/js/app.js @@ -369,9 +369,7 @@ function updateDashboard() { renderSdTop3(total); // Infraestructura - const inf = { srv: num('in_inf_srv'), lan: num('in_inf_lan'), wifi: num('in_inf_wifi'), isp: num('in_inf_isp') }; - renderInfra(inf); - + renderInfra(); + renderHosts(); // <-- new call Below is the new function (added near the bottom of the file for readability):
/** * Render the Hosts / Collaborators widget. * Expects API payload: * [{ location: "Cancun", hosts: [{ name, role }, ...] }, ...] */ function renderHosts() { const container = document.querySelector('.hosts-widget'); if (!container) return; fetch('/api/data/hosts') .then(r => r.json()) .then(data => { // Clear previous content container.innerHTML = `<h4>Hosts by Location</h4><ul></ul>`; const list = container.querySelector('ul'); data.forEach(loc => { const li = document.createElement('li'); const hostNames = loc.hosts.map(h => `${h.name} (${h.role})`).join(', '); li.textContent = `${loc.location}: ${hostNames}`; list.appendChild(li); }); }) .catch(err => { console.error('Failed to load hosts:', err); container.innerHTML = '<p class="error">Unable to load hosts.</p>'; }); } Design notes:
- Separation of concerns – The function only handles rendering; data fetching stays inside the function to keep the UI logic self‑contained.
- Graceful degradation – If the fetch fails, we display a user‑friendly error instead of breaking the whole dashboard.
5. Bump the client‑side script version
To bust caches on production, I updated the script query string in public/index.html.
--- a/public/index.html +++ b/public/index.html @@ -982,6 +982,6 @@ <h3>🔑 Cambiar contraseña</h3> </div> <!-- ══════════════ SCRIPTS ══════════════ --> -<script src="/js/app.js?v=20261119h"></script> +<script src="/js/app.js?v=20261127a"></script> 6. Minor CSS tweaks for the new widget
Added a comment block in public/index.html to group the new styles with the existing “infra” section, ensuring the stylesheet remains readable.
diff @@ -430,6 +430,14 @@ .inf svg { color:#C98A1B; } .inf-l { font-size:14px; font-weight:700; color:#162E3E; } .inf-v { font-size:26px; font-weight:700; color:#C98A1B; line-height:1.1; } +/* Hosts widget – multiple properties */ +. --- *Part of my [Build in Public](https://dev.to/zaerohell) series — sharing the real process of building SaaS projects from Playa del Carmen, México.* *Repo: `zaerohell/hotel-it-ops-dashboard` · 2026-11-27* \#playadev #buildinpublic 
