Skip to content

Fix/ issue #50#61

Open
therealjhay wants to merge 5 commits into
Chainmove:mainfrom
therealjhay:fix/-issue-#50
Open

Fix/ issue #50#61
therealjhay wants to merge 5 commits into
Chainmove:mainfrom
therealjhay:fix/-issue-#50

Conversation

@therealjhay

Copy link
Copy Markdown
  1. Core Risk Logic & Query Builders
    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

@Obiajulu-gif

Copy link
Copy Markdown
Collaborator

@therealjhay great job, fix the ci/cd and i will merge

@therealjhay

Copy link
Copy Markdown
Author

Removed the unused mongoose import from lib/risk-helpers.ts.
Type-casted the sort values using as const (e.g., { failedCount: -1 as const }) to ensure Mongoose accepts them as valid literal directions in its aggregation pipeline type definitions.

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.

[HARD][DASHBOARD] Build admin risk analytics dashboard for repayment and funding anomalies

2 participants