fix(referrals): credit referrer bonus on first module completion - #21
Merged
merlik787-droi merged 2 commits intoAug 19, 2026
Merged
Conversation
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
requested changes
Aug 19, 2026
merlik787-droi
left a comment
Contributor
There was a problem hiding this comment.
Resolve conflicts
5 tasks
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.
Summary
Fixes #11:
ReferralController.processReferralBonuswas dead code, so a referrer whose referee completed their first module was never credited in real traffic.Changes
ReferralController.processReferralBonusintocompleteModuleso the referee's first completion credits the referrer.syncCompletionsso first completions arriving via sync also unlock the bonus.bonusPaidtransition atomic with a conditionalupdateMany({ where: { id, bonusPaid: false } })that verifies one row was affected, preventing double-pay under concurrent first-completions.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 missingquizQuestionmock 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 passpnpm lint— cleanCloses #11