feat: add parseCreatorId helper and integrate into creator ID handlers (#468) - #501
Merged
Conversation
- Add parseCreatorId(raw): number utility that validates positive integer and throws 400 ApiError on invalid input - Replace manual creator ID coercion in creator detail, holders, and webhook handlers with the shared helper - Add unit tests covering valid, float, negative, non-numeric, empty, whitespace, trailing chars, and zero edge cases Closes accesslayerorg#468
|
@K1NGD4VID 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! 🚀 |
… passing to parseCreatorId
3 tasks
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
Creator ID params arrive as strings from the URL but are stored as integers in the database. Each handler previously coerced the type independently. This PR adds a shared
parseCreatorIdhelper that parses and validates a creator ID string at the start of every handler that accepts a creator ID.Closes #468
Changes
New:
src/utils/creator-id.utils.tsparseCreatorId(raw: string): number— validates input is a positive integer and returns the parsed number. Throws a 400ApiError(viavalidationError) for: empty strings, whitespace-only, non-numeric, floats, negatives, and zero.Modified:
src/modules/creators/creators.controllers.tshttpGetCreatorStats— replaced manualreq.params.idexistence/type check withparseCreatorId(req.params.id)Modified:
src/modules/creators/creator-holders.controller.tshttpGetCreatorHolders— replacedtypeof rawId ===string? rawId : String(rawId ?? )withparseCreatorId(req.params.id)Modified:
src/modules/webhooks/webhook-signature.middleware.tsrequireWalletSignature— replaced rawreq.params.idextraction + null check withparseCreatorId(req.params.id)(inside try/catch since this middleware lacks async error handling)New:
src/utils/test/creator-id.utils.test.tsAcceptance Criteria
Notes