Fixing the “D.map is not a function” crash by tightening DB indexes and normalizing the API payload

TL;DR: I added missing PostgreSQL indexes in apps/api/src/db/db.ts and forced the /condos/metrics endpoint to always return an array. The change stopped the runtime TypeError: D.map is not a function in the React selector and restored correct KPI calculations.

The Problem

Our internal “Condo Dashboard” started throwing a JavaScript error in production:

TypeError: D.map is not a function