Implement Request Validation Middleware (#112)#134
Merged
llinsss merged 1 commit intollinsss:masterfrom Feb 19, 2026
Merged
Conversation
…d schemas and integrate it into relevant API routes.
👷 Deploy request for taggedpay pending review.Visit the deploys page to approve it
|
|
@Adedayo-Data is attempting to deploy a commit to the llinsomoudu-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
llinsss
approved these changes
Feb 19, 2026
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.
Overview
Closes #112 — adds comprehensive request validation across all backend endpoints using Joi schemas and a centralized validation middleware.
What Was Already Done
middleware/validation.jsexisted withvalidate,validateQuery,validateParamshelpersschemas/auth.jshad basic register/login schemas (wired correctly)schemas/payment.jshad a comprehensiveprocessPaymentSchemaroutes/auth.jswas correctly wired with validationWhat This PR Fixes & Adds
middleware/validation.jsabortEarly: falseso all field errors are returned at once instead of just the first{ errors: [{ field, message }] }across all three validators (validate,validateQuery,validateParams)schemas/auth.js.messages()with user-friendly text on all fieldstagschemas/balance.jsJoi.any()fields with properly typed validators (string,number, etc.)schemas/transaction.jsJoi.any()fields intransactionSchemawith typed, validated fieldstypeandstatusfieldstransactionQuerySchemawith.messages()schemas/kyc.js(was completely empty)kycCreateSchema— all required identity fields (first_name,last_name,dob,country,id_type,id_number)kycUpdateSchema— partial update schema (minimum 1 field required)schemas/user.js(new)editProfileSchema— validates the profile edit endpoint; whitelists only safe fields (tag,phone,avatar_url,full_name), preventing mass assignmentschemas/wallet.js(new)sendToTagSchema— validates tag format, positive amount, and balance IDsendToWalletSchema— validates receiver address, positive amount, and balance IDRoute Wiring
POST /transactions/paymentvalidate(processPaymentSchema)— was missingPOST /kycs/validate(kycCreateSchema)PUT /kycs/:idvalidate(kycUpdateSchema)POST /balances/validate(balanceCreateSchema)POST /users/profilevalidate(editProfileSchema)POST /wallets/send-to-tagvalidate(sendToTagSchema)POST /wallets/send-to-walletvalidate(sendToWalletSchema)Tests (
tests/validation.test.js) (new)Files Changed
backend/middleware/validation.js — modified
backend/schemas/auth.js — modified
backend/schemas/balance.js — modified
backend/schemas/transaction.js — modified
backend/schemas/kyc.js — modified (was empty)
backend/schemas/user.js — new
backend/schemas/wallet.js — new
backend/routes/transactions.js — modified
backend/routes/kycs.js — modified
backend/routes/balances.js — modified
backend/routes/users.js — modified
backend/routes/wallets.js — modified
backend/tests/validation.test.js — new
backend/package.json — added jest + supertest dev deps, test script
How to Run Tests
Validation Error Response Format
All validation failures now return a consistent shape:
{ "errors": [ { "field": "email", "message": "Please provide a valid email address" }, { "field": "password", "message": "Password must be at least 8 characters long" } ] }