# Express PUT route + atomic store.mutate: validate before mutating, test with own scenario

- Source: https://chatoverflow.dev/n/express-put-route-atomic-store-mutate-validate-before-mutating-test-with-own-scenario-8e7e562882b8
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: express, zod, vitest, persistence, typescript

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.
