Skip to content

feat: Referral Program API (#50)#56

Merged
Kaylahray merged 2 commits into
learnault:mainfrom
nonsobethel0-dev:feat/referral-program-api
Apr 27, 2026
Merged

feat: Referral Program API (#50)#56
Kaylahray merged 2 commits into
learnault:mainfrom
nonsobethel0-dev:feat/referral-program-api

Conversation

@nonsobethel0-dev
Copy link
Copy Markdown
Contributor

Fixes #50

What changed

  • Added ReferralCode and Referral Prisma models to support referral persistence
  • POST /api/v1/referrals/code — generates a unique referral code for the authenticated user (idempotent: returns existing code if one already exists)
  • POST /api/v1/referrals/apply — attaches a referral code during signup/onboarding with anti-abuse guards
  • GET /api/v1/referrals/stats — returns total referrals, active referrals (referees who completed ≥1 module), earned bonuses, and pending bonuses
  • ReferralController.processReferralBonus static method to award bonus to referrer after referee completes their first module
  • Anti-abuse: self-referral prevention, duplicate referral rejection

Why

  • Referral system drives user growth by rewarding existing learners who bring in active new users
  • Bonus is gated behind the referee completing their first module to ensure quality referrals

How to test

  • POST /api/v1/referrals/code with a valid bearer token → should return a unique code
  • POST /api/v1/referrals/apply with another user's token and { "code": "<code>" } → referral should be recorded
  • Attempt self-referral → expect 400 error
  • Attempt applying a code twice → expect 409 error
  • GET /api/v1/referrals/stats → should show correct counts and bonus amounts
  • After referee completes a module, call ReferralController.processReferralBonus(refereeId) → referrer bonus should be recorded

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 27, 2026

@nonsobethel0-dev 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

@Kaylahray
Copy link
Copy Markdown
Contributor

please resolve conflicts @nonsobethel0-dev

- Add ReferralCode and Referral models to Prisma schema
- POST /referrals/code — generate unique referral code per user
- POST /referrals/apply — attach referral code with self-referral and duplicate prevention
- GET /referrals/stats — referral count, active referrals, earned bonuses
- Bonus unlocked only after referred user completes first module
- Unit tests covering all endpoints and edge cases
- Fix ESLint newline-before-return error in generateCode handler
- Replace await on asyncHandler-wrapped calls with flushPromises helper
  to correctly drain the microtask queue before asserting on next()
@nonsobethel0-dev nonsobethel0-dev force-pushed the feat/referral-program-api branch from 1c1e869 to 2160d29 Compare April 27, 2026 11:27
@Kaylahray Kaylahray merged commit a1e1ead into learnault:main Apr 27, 2026
1 check passed
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.

2 participants