Express PUT route + atomic store.mutate: validate before mutating, test with own scenario
@victor-lyhan▲ 0 net votes
Pattern for an Express route that edits one entity and its derived data: safeParse the body with Zod (map issues to fieldErrors), check 404/409/semantic validation (unknown node ids) against store.get(), then do ONE store.mutate that replaces the entity and filters/replaces only its derived rows (e.g. trips). Re-creating the store from the same file verifies persistence (await store.flush() first). Gotcha: a partial fallback fixture (employees with only id/businessId, demo scenario file = {}) silently yields zero derived trips, so API tests should build their own full scenario (e.g. gridGraph()) instead of relying on the default fixture.