Fix/ issue #50#61
Open
therealjhay wants to merge 5 commits into
Open
Conversation
Collaborator
|
@therealjhay great job, fix the ci/cd and i will merge |
Author
|
Removed the unused mongoose import from lib/risk-helpers.ts. |
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.
We created a new backend utility file at lib/risk-helpers.ts. It houses modular Mongoose query filters and aggregation pipelines for 5 distinct risk rules:
Late Repayments: Flags active contracts past their due dates.
Failed Transactions: Identifies users exceeding a specific number of failed payment attempts within a set timeframe.
Inactive Contracts: Flags active contracts with no recent updates or activity.
Underperforming Pools: Identifies investment pools where actual funds raised fall below expected/target thresholds.
High-Value Wallet Funding: Flags abnormally large wallet deposits.
2. Secure API Endpoints
We exposed the risk queries to the frontend by building two secure API routes in app/api/admin/risk/:
summary/route.ts: Runs all 5 queries in parallel using Promise.all to quickly return high-level counts for dashboard widgets.
details/route.ts: A robust, paginated endpoint that accepts query parameters (like type, page, limit, daysInactive, etc.) to return detailed records. It also automatically populates relevant user data (like name and email) from the database.
Security: Both routes are strictly protected by your getAuthenticatedUser middleware, returning a 403 Forbidden for any non-admin users.
3. Visual UI Components
We built four presentational components in components/admin/risk/ using your shadcn/ui library:
RiskSummaryCards: A responsive row of metric cards with loading states and quick-scan icons.
RiskFilterBar: A controlled filter bar handling Risk Type, Review Status, User Role, and Date Range inputs.
RiskDataTable: A clear table to list flagged entities, dates, custom risk signals, and review statuses.
RiskDetailModal: A slide-out dialog that displays the full context of a flagged record and provides placeholder action buttons (e.g., "Suspend Entity", "Mark as Resolved").
4. Dashboard Integration
Finally, we wired it all together in the main page component at app/admin/risk/page.tsx:
We used React useEffect and standard fetch to retrieve the summary and detail data.
We implemented robust state management to handle loading skeletons, empty states (when no records match filters), and error states (displaying red alerts if fetching fails).
The interactive RiskFilterBar automatically triggers data re-fetches when parameters change, and clicking on any table row correctly opens the RiskDetailModal.
Closes #50