feat(api): implement campaign stats, suspension, close, and category …#267
Merged
Conversation
|
@feyishola 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! 🚀 |
ayshadogo
approved these changes
Jun 1, 2026
Contributor
ayshadogo
left a comment
There was a problem hiding this comment.
LGTM
Thank you for your contribution
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.
…endpoints
Summary
This PR implements four campaign management endpoints enabling detailed analytics, admin moderation, creator-driven closure, and category-based discovery.
Changes Included
File: src/routes/campaigns.ts, src/services/campaignStats.ts, tests/campaigns/stats.test.ts
Auth: Creator or admin only
Returns:
typescript
{
totalRaised: string; // Total donations in base units
donorCount: number; // Unique donor addresses
uniqueAssets: number; // Distinct NFT/assets donated
avgDonation: string; // Average donation amount
donationsPerDay: Array<{ // Last 30 days
date: string;
amount: string;
count: number;
}>;
topDonors: Array<{ // Top 5 by total amount
address: string;
totalAmount: string;
donationCount: number;
}>;
}
Data Source: Aggregated from donations table
File: src/routes/admin.ts, src/services/campaignSuspension.ts, tests/admin/suspend.test.ts
Auth: ADMIN role required
Request Body: { reason: string }
Actions:
Sets campaign status to SUSPENDED
Sends email notification to creator
Logs suspension in AuditLog table
Returns suspension details with timestamp
File: src/routes/campaigns.ts, src/services/campaignClosure.ts, tests/campaigns/close.test.ts
Auth: Creator only with wallet signature verification
Request Body: { signature: string, timestamp: number, message: string }
Security: Replay protection via signed payload + timestamp validation
Actions:
Sets campaign status to CLOSED
Triggers email notifications to all donors
Records close event in AuditLog
Returns closure confirmation
File: src/routes/campaigns.ts, src/services/campaignCategories.ts, tests/campaigns/categories.test.ts
Endpoint A: GET /campaigns?category=health
Filters campaigns by category
Supports pagination (limit/offset)
Returns campaign list with metadata
Endpoint B: GET /campaigns/categories
Returns all categories with campaign counts
{
categories: Array<{
id: string;
name: string;
campaignCount: number;
totalRaised: string;
}>;
}
Categories: health, education, environment, disaster-relief, community, other
closes #253
closes #254
closes #255
closes #256