fix: attach auditLog middleware to JWT admin dispute endpoints#41
Open
AbuJulaybeeb wants to merge 2 commits into
Open
fix: attach auditLog middleware to JWT admin dispute endpoints#41AbuJulaybeeb wants to merge 2 commits into
AbuJulaybeeb wants to merge 2 commits into
Conversation
ogazboiz
requested changes
Jun 23, 2026
ogazboiz
left a comment
Contributor
There was a problem hiding this comment.
this is correct, the auditLog middleware is attached on both /disputes/:disputeId/resolve and /disputes/:disputeId/reject after requireJwtAuth + requireRoles("admin") so req.user.publicKey is the actor, it's a real INSERT into audit_logs (columns match migration 1780000000010), and the DB write is fire-and-forget with its own try/catch + logger.error and a synchronous next(), so a DB error can't block or crash the request. nice. one mechanical thing:
- prettier fails on src/tests/loanDispute.test.ts (CI's lint step fails the whole job on it). run: npx prettier --write src/tests/loanDispute.test.ts
fix that and it's good to merge.
if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
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.
This PR resolves an issue where the JWT-protected admin dispute endpoints (/disputes/:disputeId/resolve and /disputes/:disputeId/reject) were not logging audit events, despite modifying loan default status.
What was done:
Added the auditLog middleware to POST /disputes/:disputeId/resolve and POST /disputes/:disputeId/reject in src/routes/adminRoutes.ts.
Updated the extractTarget function in src/middleware/auditLog.ts to properly identify and extract disputeId from the request parameters (logging as DisputeID:).
Included a test in src/tests/loanDispute.test.ts to assert that the audit_logs insertion query fires upon JWT resolution, ensuring the admin public key is recorded while sensitive fields (like tokens/passwords) remain successfully redacted by the sanitizer.
How it was verified:
Verified standard unit tests via Jest pass smoothly without mock conflicts.
Verified test specifically tracks and logs the payload safely while confirming JWT endpoint triggers the asynchronous INSERT INTO audit_logs properly.
closes #13