fix(onboarding): tidy the small edges around the setup routes

Four of them. The confirm re-stamped its completion instant on every call, so
a replay quietly moved the moment the setup finished at while the derivation
beside it was carefully latched. The two list answers were stored exactly as
sent, duplicates included, so the column could hold something the reader would
never return — the reader de-duplicates on the way out and now so does the
write. The wide-event name for saving an answer used a different noun from its
two siblings, which makes a dashboard filter awkward for one feature. And the
contract said the restart body was required while the route accepts none.
This commit is contained in:
Marc-André Bombeck committed 2026-09-10 12:14:32 +02:00
1 parent b17f18295e
commit 44b6ea01c6
7 files changed
+51 -9

No files matched your search

+4 -4
View File
@@ -51,7 +51,7 @@ const RATE_WINDOW_MS = 10 * 60 * 1000;
export const PATCH = apiHandler(async (request: NextRequest) => {
const { user } = await requireAuth();
annotate({ action: { name: "onboarding.answer.save" } });
annotate({ action: { name: "onboarding.needs.save" } });
const rl = await checkRateLimit(
`onboarding-answers:${user.id}`,
@@ -60,7 +60,7 @@ export const PATCH = apiHandler(async (request: NextRequest) => {
);
if (!rl.allowed) {
annotate({
action: { name: "onboarding.answer.save" },
action: { name: "onboarding.needs.save" },
meta: { outcome: "rate_limited" },
});
return apiError("Too many onboarding writes, try again later", 429, {
@@ -76,7 +76,7 @@ export const PATCH = apiHandler(async (request: NextRequest) => {
const parsed = onboardingAnswerSchema.safeParse(body);
if (!parsed.success) {
annotate({
action: { name: "onboarding.answer.save" },
action: { name: "onboarding.needs.save" },
meta: { outcome: "validation_failed" },
});
return returnAllZodIssues(parsed.error, 422, {
@@ -175,7 +175,7 @@ export const PATCH = apiHandler(async (request: NextRequest) => {
}
annotate({
action: { name: "onboarding.answer.save" },
action: { name: "onboarding.needs.save" },
meta: {
step: answer.step,
status: answer.status === "skipped" ? "skipped" : "done",
+4 -1
View File
@@ -236,7 +236,10 @@ async function completeNeedsFlow(
where: { userId },
data: {
stepsJson: toJson(confirmed),
completedAt: now,
// Stamped once. The derivation is latched and the stamp should be too,
// or a replay of the confirm quietly moves the instant the setup
// finished at.
completedAt: record.completedAt ?? now,
...(derived ? { modulesDerivedAt: now } : {}),
},
select: ONBOARDING_RECORD_SELECT,