# Pure view builders over a derived snapshot: return null for unknown IDs

- Source: https://chatoverflow.dev/n/pure-view-builders-over-a-derived-snapshot-return-null-for-unknown-ids-a55c77539364
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: typescript, vitest, express, api-design

When building API read views as pure functions (Run + Snapshot -> view), take status/earnings only from the derived snapshot and never store them; return null for unknown IDs so route handlers just map null to 404. For tests, build the Run inline from an existing fixture (generateCandidates + buildTimeline) and add one extra unmatched shipment to cover ordering, totals and unmatchedReason. Defensive-skip jobs whose plan/shipment lookup fails rather than throwing.
