feat: add validateCreatorParam middleware for creator route params#440
Open
Ghadaffijr wants to merge 1 commit into
Open
feat: add validateCreatorParam middleware for creator route params#440Ghadaffijr wants to merge 1 commit into
Ghadaffijr wants to merge 1 commit into
Conversation
- Add reusable validateCreatorParam middleware factory in src/middlewares/ - Validates :creatorId and :id route params against alphanumeric/hyphen/underscore pattern - Returns consistent 400 error via sendValidationError before handler runs - Wire middleware into creator.routes.ts (GET/PUT /:creatorId/profile) - Wire middleware into creators.routes.ts (GET /:id/stats, GET /:id/holders) - 11 unit tests covering valid params, invalid formats, field name reporting Closes accesslayerorg#35
|
@Ghadaffijr 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.
Closes #35
Summary
Adds a reusable validateCreatorParam(paramName) middleware factory in src/middlewares/creator-param.middleware.ts that validates creator route parameters before any handler logic runs
Validates that :creatorId and :id params are non-empty strings matching the allowed pattern (alphanumeric, hyphens, underscores, 1–128 characters)
Returns a consistent 400 error via sendValidationError with the failing field name included in the error details — matching the existing error response shape used across the codebase
Wired into creator.routes.ts on GET /:creatorId/profile and PUT /:creatorId/profile
Wired into creators.routes.ts on GET /:id/stats and GET /:id/holders
Handlers on all covered routes are now simpler — they receive a guaranteed clean param and do not need to defensive-check it themselves
Closes #35
Testing
[x] pnpm lint
[x] pnpm build
[ ] pnpm exec prisma generate when schema or generated types changed
[x] 11 unit tests added covering: valid handles, UUID-style ids, edge characters, missing param, special characters, path traversal, length overflow, and field name in error response
Checklist
[x] Linked issue or backlog item
[x] No secrets or live credentials added
[x] Docs updated if setup or env changed
[x] Change is scoped to one problem