feat(api): let a record answer the setup questions, and act on them

Three writes, all on the caller's own record.

`PATCH /api/onboarding/answers` saves one step the moment it is answered, so
leaving the flow and coming back resumes where it stopped. It is idempotent
because the whole computation is a pure function of the row and the body,
including the first-result instant, which is kept rather than re-taken. There is
no ordering contract at all: a back button has to work.

`POST /api/onboarding/complete` keeps everything it did and gains the confirm
screen's job. For a record that answered the questions it derives the module map
once and applies it, and the once-only latch is the point: a second confirm
would re-apply a questionnaire over decisions taken in Settings since. Cycle is
switched on through its own column and never off, because the gate already
derives an unanswered cycle from recorded sex and an untick is not a request to
retract that.

`POST /api/onboarding/restart` puts the steps back and clears the latch. It
writes no module state whatever: a re-run never turns off something switched on
by hand, and the safest way to hold that is for this route to have no opinion
about modules at all. It also leaves the first-run redirect's own stamp alone,
so asking the questions again does not push anybody back through the old wizard.

All three refuse outright while the session is acting on somebody else's record,
at every grant level, so a delegate can never write another record's setup. The
route into a managed profile's flow belongs with the rest of that record's
configuration and is not smuggled in here.

The demo allowlist gains the three: the flow has to be completable there with
preset answers, and none of them creates health data.
This commit is contained in:
Marc-André Bombeck committed 2026-09-10 11:03:36 +02:00
1 parent cc98c56172
commit 021ea8f1ff
5 files changed
+587 -6

No files matched your search

+8
View File
@@ -158,6 +158,14 @@ const DEMO_MUTATION_ALLOWLIST: ReadonlyArray<{ path: string; method: string }> =
// Chart display-pref toggles above the charts (dashboard + insights):
{ path: "/api/dashboard/chart-overlay-prefs", method: "PUT" },
{ path: "/api/dashboard/widgets", method: "PUT" },
// v1.39 (C1) — the needs-based setup flow, which the demo has to be able
// to complete with preset answers (design spec §Principles 5). All three
// are user-scoped preference writes: closed enum answers, the step ledger,
// and the module map derived from them. No health data is created by any
// of them, and the demo account's own record is the only thing they touch.
{ path: "/api/onboarding/answers", method: "PATCH" },
{ path: "/api/onboarding/complete", method: "POST" },
{ path: "/api/onboarding/restart", method: "POST" },
];
// Legacy route redirects (German → English)