Skip to content

Extract shared parseBody helper for Zod validation - #598

Merged
selfcontained merged 3 commits into
mainfrom
agt_b578a4e849c7/job-debt-collector-d3a1f850
May 22, 2026
Merged

Extract shared parseBody helper for Zod validation#598
selfcontained merged 3 commits into
mainfrom
agt_b578a4e849c7/job-debt-collector-d3a1f850

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • Extracts a shared parseBody() helper into apps/server/src/shared/lib/parse-body.ts that wraps the Zod safeParse + 400 error reply pattern
  • Replaces 13 identical 3-line boilerplate blocks across auth.ts (3), jobs.ts (7), and templates.ts (3) with one-line parseBody() calls
  • Net reduction: 66 lines removed, 58 added (including the new helper file)

Why this is tech debt

The safeParse → check !parsed.successreply.code(400).send({ error: parsed.error.issues[0].message }) pattern was copy-pasted verbatim across every route handler that validates request bodies. This made it easy to forget or subtly vary the error format, and added visual noise to every handler.

What's next

Next tech debt run will tackle: duplicate constraint-error handler in personalities.ts (lines 60-67 and 120-127 have identical catch blocks).

🤖 Generated with Claude Code

selfcontained and others added 3 commits May 22, 2026 03:07
…late

Replaces 13 identical safeParse + error-reply blocks across auth.ts,
jobs.ts, and templates.ts with a single shared parseBody() function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addresses architecture review feedback:
- Renamed parseBody→parseInput since it validates both body and query
- Constrained generic from ZodType to ZodObject so the undefined-check
  guard is safe (objects are never falsy)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Completes the round-2 review feedback: the module file now matches
the exported parseInput function name.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@selfcontained
selfcontained merged commit c69e638 into main May 22, 2026
1 check passed
@selfcontained
selfcontained deleted the agt_b578a4e849c7/job-debt-collector-d3a1f850 branch May 22, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant