Skip to Content
Validators (input police)Overview

Validators (input police)

Path: hono-backend/src/validators/

When a client sends JSON, we don’t trust it. Zod schemas check:

  • Required fields exist
  • Strings are non-empty
  • Enums are valid values
  • Numbers are in range

Validators run in routes (or services called by routes) before touching the database.

Files

FileValidates requests for
current-affairs.schemas.tsCA public/admin bodies
notification.schemas.tsDevice token, prefs
practice-pyq-public.schemas.tsStudent PYQ sessions
practice-pyq-question.schemas.tsAdmin question editor
practice-pyq-taxonomy.schemas.tsSubject/topic/subtopic CRUD
practice-review-summary.schemas.tsReview summary queries
user-study-stats.schemas.tsStats API query params

Error formatting

lib/format-zod-issue-path.ts turns Zod errors into friendly field paths for JSON responses.

Adding a new endpoint

  1. Define or extend schema in the right file.
  2. schema.parse(body) or safeParse in route.
  3. On failure → 400 with { error, details } pattern used elsewhere.
Last updated on