Skip to content

feat: add validateCreatorParam middleware for creator route params#440

Open
Ghadaffijr wants to merge 1 commit into
accesslayerorg:mainfrom
Ghadaffijr:feat/creator-route-param-validation
Open

feat: add validateCreatorParam middleware for creator route params#440
Ghadaffijr wants to merge 1 commit into
accesslayerorg:mainfrom
Ghadaffijr:feat/creator-route-param-validation

Conversation

@Ghadaffijr

Copy link
Copy Markdown
  • 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 #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

- 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
@drips-wave

drips-wave Bot commented Jun 24, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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.

Add creator route param validation middleware

1 participant