Skip to content

Commit

Permalink
Create referralProgram.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 3, 2024
1 parent d68216f commit bb83336
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/loyalty/referralProgram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// referralProgram.js

class ReferralProgram {
constructor() {
this.referrals = {}; // Store referrals by user ID
this.rewards = {}; // Store rewards by user ID
}

// Refer a new user
refer(referrerId, referredId) {
if (!this.referrals[referrerId]) {
this.referrals[referrerId] = [];
}
this.referrals[referrerId].push(referredId);
console.log(`User ${referrerId} referred ${referredId}.`);
}

// Reward the referrer for a successful referral
rewardReferrer(referrerId) {
if (!this.rewards[referrerId]) {
this.rewards[referrerId] = 0;
}
this.rewards[referrerId] += 50; // Example reward amount
console.log(`User ${referrerId} has been rewarded. Total rewards: $${this.rewards[referrerId]}`);
}

// Get referral details for a user
getReferralDetails(userId) {
return {
referrals: this.referrals[userId] || [],
rewards: this.rewards[userId] || 0,
};
}
}

// Example usage
const referralProgram = new ReferralProgram();
referralProgram.refer('user123', 'user456');
referralProgram.rewardReferrer('user123');

const referralDetails = referralProgram.getReferralDetails('user123');
console.log(`Referral details for user123:`, referralDetails);

export default ReferralProgram;

0 comments on commit bb83336

Please sign in to comment.