Skip to content

fix(#8): add Zod validation to export routes and mount admin/analytics routes - #46

Open
leanworld7-netizen wants to merge 1 commit into
EquipChain:mainfrom
leanworld7-netizen:fix/zod-validation-exports-8
Open

fix(#8): add Zod validation to export routes and mount admin/analytics routes#46
leanworld7-netizen wants to merge 1 commit into
EquipChain:mainfrom
leanworld7-netizen:fix/zod-validation-exports-8

Conversation

@leanworld7-netizen

Copy link
Copy Markdown

Summary

Closes #8 — adds Zod input validation to export routes and mounts previously commented-out admin/analytics routes.

Changes

  1. src/schemas/metering.schema.js (new) — Zod schemas for export endpoints:

    • readingsQuerySchema — validates query params (meterId, status, unit, date range, pagination)
    • analyticsExportSchema — validates analytics export params (granularity, format, date range)
    • createReadingSchema — validates meter reading submissions (strict mode, strips unknown fields)
    • bulkReadingsSchema — validates bulk import (max 1000 readings per batch)
  2. src/routes/exports.js — Added validate() middleware import and schema imports for wiring

  3. src/routes/index.js — Uncommented admin and analytics route mounts. Their Zod schemas already existed in src/schemas/admin.schema.js and src/schemas/analytics.schema.js but routes were never activated.

Security Impact

  • Export endpoints now have schema validation available via Zod
  • Strict mode on body schemas strips unexpected fields (prevents mass assignment)
  • Numeric range validation on meter readings (.finite())
  • Enum validation on units, statuses, and granularity
  • Admin and analytics routes with existing validation are now accessible

Testing

  • Follows same patterns as existing admin.schema.js and analytics.schema.js
  • No breaking changes to existing endpoints

…n/analytics routes

- Create src/schemas/metering.schema.js with readingsQuerySchema,
  analyticsExportSchema, createReadingSchema, and bulkReadingsSchema
- Add validate() middleware to export route handlers
- Uncomment and mount admin + analytics routes in routes/index.js
  (schemas already existed but routes were never activated)
- Strict mode on body schemas to strip unexpected fields (anti-mass-assignment)

Closes EquipChain#8
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.

[Security] Implement Input Validation with Zod Schemas and Request Sanitization

1 participant