refactor: Zod schemas and unified body validation (#356)#375
Open
DammyAji wants to merge 1 commit into
Open
Conversation
- Install zod@3.24.2 - Add validateBody(schema) middleware with uniform error envelope (VALIDATION_ERROR code, sorted details, unknown fields stripped) - Add CreateSlotBodySchema and CreateBookingIntentBodySchema in src/middleware/schemas.ts - Migrate POST /api/v1/slots: replace validateRequiredFields with validateBody(CreateSlotBodySchema) - Migrate POST /api/v1/booking-intents: remove parseCreateBookingIntentBody, add validateBody(CreateBookingIntentBodySchema) - Fix missing createCORSMiddleware import in src/app.ts - Add 20 tests in src/__tests__/zod-validation.test.ts (all passing) Closes Chronopay-Org#356
58b60a6 to
8b4c929
Compare
|
@DammyAji Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #356
Centralizes request body validation on Zod schemas with a single
validateBody(schema)middleware producing uniform error envelopes across all routes.Changes
zod@3.24.2added as a dependencysrc/middleware/validation.ts— newvalidateBody<T>(schema)middleware:{ success: false, code: "VALIDATION_ERROR", error, details[] }(path ASC, rule ASC)for deterministic outputsrc/middleware/schemas.ts— per-route Zod schemas:CreateSlotBodySchema—professional(non-empty string),startTime/endTime(number or ISO-8601)CreateBookingIntentBodySchema—slotId(slot-uuid pattern),note(optional, max 500 chars)src/routes/slots.ts—validateRequiredFieldsreplaced withvalidateBody(CreateSlotBodySchema)src/routes/booking-intents.ts—parseCreateBookingIntentBodyremoved,validateBody(CreateBookingIntentBodySchema)addedsrc/app.ts— fixed missingcreateCORSMiddlewareimport (pre-existing bug)src/__tests__/zod-validation.test.ts— 20 tests, all passingTest output