Skip to content

fix(referrals): credit referrer bonus on first module completion - #21

Merged
merlik787-droi merged 2 commits into
Kqirox:mainfrom
Degentle12:fix/referral-bonus-dead-code
Aug 19, 2026
Merged

fix(referrals): credit referrer bonus on first module completion#21
merlik787-droi merged 2 commits into
Kqirox:mainfrom
Degentle12:fix/referral-bonus-dead-code

Conversation

@Degentle12

Copy link
Copy Markdown
Contributor

Summary

Fixes #11: ReferralController.processReferralBonus was dead code, so a referrer whose referee completed their first module was never credited in real traffic.

Changes

  • Wire ReferralController.processReferralBonus into completeModule so the referee's first completion credits the referrer.
  • Wire the same hook into offline syncCompletions so first completions arriving via sync also unlock the bonus.
  • Make the bonusPaid transition atomic with a conditional updateMany({ where: { id, bonusPaid: false } }) that verifies one row was affected, preventing double-pay under concurrent first-completions.
  • Update the Swagger referral description and README to document that the bonus is now automatic.

Tests

  • tests/unit/module.controller.test.ts: asserts completion credits the referrer, does not double-pay a second time, and still completes when bonus processing fails. Also fixes a pre-existing missing quizQuestion mock in the webhook test.
  • tests/referral.controller.test.ts: atomic conditional-update behavior plus no-double-pay coverage.
  • tests/sync.controller.test.ts: bonus triggered on an offline first completion.

Verification

  • pnpm test:ci — 308 tests pass
  • pnpm lint — clean

Closes #11

processReferralBonus was dead code, so a referrer whose referee
completed their first module was never paid in real traffic. Wire it
into completeModule and offline syncCompletions, and make the bonusPaid
transition atomic with a conditional updateMany so concurrent
first-completions cannot double-pay.

Closes Kqirox#11

@merlik787-droi merlik787-droi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolve conflicts

@merlik787-droi merlik787-droi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@merlik787-droi
merlik787-droi merged commit b5a50ef into Kqirox:main Aug 19, 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.

Referral bonuses are never paid in the real flow: processReferralBonus is dead code

2 participants