Repository navigation
feat: add referral program with commission structure and fraud detection - #124
Merged
heymariam merged 2 commits intoOct 8, 2026
Merged
Conversation
- Add ReferralTier, ReferralCode, Referral, ReferralCommission Prisma models - Add migration SQL (20260927180000_add_referral_program) - Implement ReferralService: code generation, referral tracking, commission calculation, payout, fraud detection (self-referral, duplicate, depth, velocity, locked-code guards), tier CRUD, affiliate dashboard - Add referral routes: GET my-code, GET dashboard, POST payout, GET code/:code (public), admin tier/code/fraud management endpoints - Hook commission processing into payment.service updateTipStatus on tip confirmation (non-blocking, errors logged) - Register referral routes in bootstrap() - Add POST /api/v1/referrals/payout to sensitive rate-limit class - Add comprehensive unit tests for all service methods
Contributor
|
@kingsmart-sketch well done and thanks for contributing, resolve the conflicts so we can check and merge |
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.
**feat: refer
Summary
Implements a complete word-of-mouth referral system
code, share it, and earn commissions when referred users
commission tiers and manage
What
Schema & migration
Referral service
code
abused
converted on first
Routes (src/domains/referrals/referral.routes.ts)
┌────────┬───────────────────────────┬──────┐
│ Method │ Path │ Auth │
├────────┼───────────────────────────┼──────┤
│ GET │ /api/v1/referrals/my-code │ User │
└────────┴───────────────────────────┴──────┘
│ GET │ /api/v1/referrals/my-code │ User │
├────────┼─────────────────────────────┼──────┤
│ GET │ /api/v1/referrals/dashboard │ User │
├────────┼─────────────────────────────┼──────┤
│ POST │ /api/v1/referrals/payout │ User │
└────────┴─────────────────────────────┴──────┘
|
| POST |
/api/v1/admin | POST |/api/v1/admin/referrals/:referralId/flag| POST
│ GET │ /api/v1/referrals/code/:code │ Public │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ GET/POST │ /api/v1/admin/referrals/tiers │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ PATCH/DELETE │ /api/v1/admin/referrals/tiers/:tierId │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/codes/:codeId/lock │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/:referralId/flag-fraud │ Admin │
├──────────────┼────────────────────────────────────────────────┼────────┤
│ POST │ /api/v1/admin/referrals/codes/:codeId/tier │ Admin │
└──────────────┴────────────────────────────────────────────────┴────────┘
**Integration
PaymentService.updateTipStatus
tip
Tests (src/domains/referrals/tests/referral.service.test.ts)
Testing
pnpm run test:
pnpm run type-check # zero type errors
p
p
Notes
prisma generate and the migration SQL
existing migrations
confirmed
▸ Credits: 0.30 • Time: 12s
⠀ Thinking... (esc to cancel)
closes #67