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
| File | Validates requests for |
|---|---|
current-affairs.schemas.ts | CA public/admin bodies |
notification.schemas.ts | Device token, prefs |
practice-pyq-public.schemas.ts | Student PYQ sessions |
practice-pyq-question.schemas.ts | Admin question editor |
practice-pyq-taxonomy.schemas.ts | Subject/topic/subtopic CRUD |
practice-review-summary.schemas.ts | Review summary queries |
user-study-stats.schemas.ts | Stats 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
- Define or extend schema in the right file.
schema.parse(body)orsafeParsein route.- On failure → 400 with
{ error, details }pattern used elsewhere.
Last updated on