Skip to content

feat(referrals): backend referral system with codes, tracking, rewards#1317

Merged
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
Icahbod:fix/issue-1091-referral-system-backend
Jun 29, 2026
Merged

feat(referrals): backend referral system with codes, tracking, rewards#1317
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
Icahbod:fix/issue-1091-referral-system-backend

Conversation

@Icahbod

@Icahbod Icahbod commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #1091
Closes #1101
Closes #1092
Closes #1093

Implements the referral system backend module (codes, tracking, rewards).

What it adds

  • New User.referralCode column (varchar, nullable, unique).
  • Referral entity with ReferralStatus (PENDING / COMPLETED) and RewardType (DISCOUNT / CREDIT) enums.
  • ReferralsService:
    • ensureReferralCode — generates an 8-hex-char MH-XXXXXXXX code and retries up to 5 times on unique-constraint collision.
    • getMyCode — returns the code plus a shareable URL, configurable via FRONTEND_URL with APP_URL and https://managehub.vercel.app fallbacks.
    • getStats — totals, conversions, total rewards earned.
    • getAll — admin-only list of every referral.
    • createReferral(referralCode, referredUserId) — idempotent on referredUserId.
    • completeReferral(referredUserId) — marks the first PENDING referral for the user as COMPLETED and defaults the reward to 10% DISCOUNT.
  • ReferralsController exposes GET /referrals/my-code, GET /referrals/stats, and GET /referrals (admin / super_admin only).
  • CreateUserDto accepts an optional referralCode (max 64 chars).
  • AuthService.createUser records the relationship when ?ref=CODE is supplied at signup, using NestJS Logger for failure visibility (a referral-tracking failure never blocks registration).
  • HandleWebhookProvider.handleChargeSuccess calls completeReferral after the booking is confirmed — fire-and-forget so payment processing is never blocked.
  • 9 Jest unit tests for ReferralsService (all green on this branch).

Out of scope

Production ALTER TABLE users ADD COLUMN referral_code varchar UNIQUE migrations — dev runs with synchronize: true, so no migration is generated. Please run the equivalent migration manually when promoting to staging / production.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Icahbod is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Icahbod 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

@yusuftomilola yusuftomilola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution

@yusuftomilola yusuftomilola merged commit 99456fd into DistinctCodes:main Jun 29, 2026
0 of 7 checks 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

2 participants