fix/api-demanda
safee65506f · incrementalPR #348reviewed 2026-07-24 20:56 UTC0H · 0M · 3L · 1I- Purpose
- Surface hiredDemand (Demanda Contratada) and connectedCharge (Carga Conectada) from CFE bill line items in the public API — fixing a gap where wizard-created contracts (null capacity columns) caused these values to be missing from GET /v1/bills.
- Goal
- Extend API_DEFAULT_CONCEPTS from 36 to 38 concepts so bill responses carry per-bill capacity values from recibo line items rather than unreliable contract columns.
- Sub-goals
- SG-1: Add hiredDemand + connectedCharge to API_DEFAULT_CONCEPTS in seed (previous commit)
- SG-2: Refresh stale '36 concepts' note to 38 (previous commit)
- SG-3: Add fields to OpenAPI example data to keep docs in sync (this commit)
- What
- Three commits: seed extends API_DEFAULT_CONCEPTS 36→38 with Spanish labels + kW units; updates stale comment; this commit mirrors both fields in the inline OpenAPI example (EXAMPLE_BILL_RESOURCE + EXAMPLE_CONCEPT_MEANING).
- Why
- A public-API customer (RPU 977251204377) reported missing demand fields. Root cause: contract-level capacity columns are null for wizard-created contracts (~1,400 in prod); recibo line items carry the values but were not surfaced. Prod config was patched live immediately; this PR keeps the seed in sync.
- Areas
- apps/platform/src/app/api/v1/openapi.json/route.ts+4−0packages/database/src/seed-column-configurations.ts+11−1
- Blast
- 2 files, +15/-1 lines. Additive-only — no existing concepts changed, no consumer breaks. Runtime behavior already deployed live separately before this commit.
Findings · 4
correctness1
connectedCharge name implies cost, but label/units describe a capacity (kW)
apps/platform/src/app/api/v1/openapi.json/route.ts:265
The field is named `connectedCharge` (implies a monetary charge) but label 'Carga Conectada' and units 'kW' describe a capacity measure. This naming is inherited from the seed config, not introduced here. Worth a follow-up rename to connectedLoad or connectedDemand.
conventions1
New demand entries not co-located with sibling kW demand fields in example
apps/platform/src/app/api/v1/openapi.json/route.ts:251
hiredDemand/connectedCharge are inserted between the kWh block and powerFactor, while the other kW demand fields (baseKw, intermediateKw, tipKw) appear later. Canonical grouping in API_DEFAULT_CONCEPTS has a dedicated 'Contract capacity (kW)' group. Non-blocking — the example is sparse and illustrative.
tests1
No assertion binding EXAMPLE_BILL_RESOURCE keys to API_DEFAULT_CONCEPTS
apps/platform/src/app/api/v1/openapi.json/route.ts:247
EXAMPLE_BILL_RESOURCE and EXAMPLE_CONCEPT_MEANING are hand-maintained with no test asserting keys are valid entries in API_DEFAULT_CONCEPTS. A typo would silently ship into public docs. Cheap fix: add Object.keys(EXAMPLE_CONCEPT_MEANING).forEach(k => expect(API_DEFAULT_CONCEPTS).toContain(k)) in docs-coverage-and-leak.test.ts.
improvement1
Identical example values for hiredDemand and connectedCharge
apps/platform/src/app/api/v1/openapi.json/route.ts:252
Both fields use '630'. Semantically valid for this CFE scenario, but distinct values (e.g. '630' / '800') would show developers these can differ per bill.