Skip to content

feat(api): implement campaign stats, suspension, close, and category …#267

Merged
ayshadogo merged 3 commits into
Dfunder:mainfrom
feyishola:feat/campaign-stats
Jun 1, 2026
Merged

feat(api): implement campaign stats, suspension, close, and category …#267
ayshadogo merged 3 commits into
Dfunder:mainfrom
feyishola:feat/campaign-stats

Conversation

@feyishola
Copy link
Copy Markdown
Contributor

…endpoints

Summary
This PR implements four campaign management endpoints enabling detailed analytics, admin moderation, creator-driven closure, and category-based discovery.

Changes Included

  1. GET /campaigns/:id/stats — Campaign Statistics
    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

  1. POST /admin/campaigns/:id/suspend — Admin Suspension
    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

  1. POST /campaigns/:id/close — Early Campaign Closure
    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

  1. Campaign Category Endpoints
    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

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@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! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

@ayshadogo ayshadogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you for your contribution

@ayshadogo ayshadogo merged commit 9316281 into Dfunder:main Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants