Skip to content

Handle referral code collisions in waitlist join - #186

Merged
terngunan merged 2 commits into
terngunan:mainfrom
josunday002:drips/100
Oct 21, 2026
Merged

terngunan merged 2 commits into
terngunan:mainfrom
josunday002:drips/100

Conversation

@josunday002

Copy link
Copy Markdown
Contributor

Summary

Handle referral code collisions in waitlist join

What was solved

#100 — waitlist.service: Hex referral code generation lacks collision retries on unique constraint conflicts

Add collision-safe referral code generation to WaitlistService::join by introducing a generateUniqueReferralCode() helper that retries generation (up to 3 attempts) and verifies absence in the repository before saving, plus a unit test in waitlist.service.spec.ts that mocks a duplicate code and asserts the retry path.

Addressed:

  • Changed: backend/src/waitlist/waitlist.service.ts, backend/src/waitlist/waitlist.service.spec.ts
  • Implement a generateUniqueReferralCode() helper in backend/src/waitlist/waitlist.service.ts that generates a hex referral code and verifies it does not already exist in the database before returning it.
  • Retry generation up to 3 attempts on collision; only throw after exhausting retries.
  • Use the helper inside WaitlistService::join so registrations do not fail on an initial random seed collision.

Changes

  • backend/src/waitlist/waitlist.service.spec.ts (modify)
  • backend/src/waitlist/waitlist.service.ts (modify)

Approach

  1. In backend/src/waitlist/waitlist.service.ts, add a private generateUniqueReferralCode() helper that generates a hex referral code and checks the repository for an existing match, retrying up to 3 attempts before throwing.
  2. Replace the inline referral code generation inside WaitlistService::join with a call to generateUniqueReferralCode().
  3. In backend/src/waitlist/waitlist.service.spec.ts, add a unit test that mocks the repository to report a duplicate code on the first check and asserts the retry path produces a unique code.
  4. Verify existing imports and repository method usage match the service's current patterns; keep all other waitlist logic untouched.

Issues

Closes #100

@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

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

@terngunan
terngunan merged commit 85441cd into terngunan:main Oct 21, 2026
0 of 2 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

Development

Successfully merging this pull request may close these issues.

waitlist.service: Hex referral code generation lacks collision retries on unique constraint conflicts

2 participants