Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: direct referral system #33

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open

Conversation

AvilaAndre
Copy link
Contributor

@AvilaAndre AvilaAndre commented Jan 7, 2025

  • Implement HashId to encode and decode referrals
  • Store referral code in the cookies on website visit
  • Create ReferralController ReferralService for giving points
    • Have a way to differentiate different user types
    • Create points field in the database
  • Implement functionality to give points to the users

Referrals are only applied after the user buys a ticket.

@AvilaAndre AvilaAndre changed the title feat: create referral middleware feature: direct referral system Jan 11, 2025
@AvilaAndre AvilaAndre linked an issue Jan 13, 2025 that may be closed by this pull request
@limwa
Copy link
Member

limwa commented Jan 19, 2025

Preview available at: https://enei-pr33.limwa.pt/
Deploy previews are kept up-to-date with the latest commits.

@tomaspalma tomaspalma changed the base branch from main to develop February 7, 2025 16:38
@AvilaAndre
Copy link
Contributor Author

@limwa should I merge ParticipantProfile and ParticipantInfo?

Also, the referred_by_promoter_id field just shows which users were referred by a promoter, do we need store who referred in the first place too? For example, if participantA used participantB's referral code and participantBs was referred by a promoterC, then the referred_by_promoter_id field on participantA will be the id of promoterC.

I could have a field referred_by which stores the id of the user who referred, whether it is a participant or a promoter (it can double as a check for if the user used a referral or not). However, for attributing points, I need the referred_by_promoter_id field as well to be able to avoid having to check who referred who recursively.

@AvilaAndre AvilaAndre marked this pull request as ready for review February 10, 2025 20:22
@limwa
Copy link
Member

limwa commented Feb 10, 2025

@limwa should I merge ParticipantProfile and ParticipantInfo?

Yes, but the migrations need to be 100% correct. We're dealing with a production system and we need to ensure that everything is perfect.

Also, the referred_by_promoter_id field just shows which users were referred by a promoter, do we need store who referred in the first place too? For example, if participantA used participantB's referral code and participantBs was referred by a promoterC, then the referred_by_promoter_id field on participantA will be the id of promoterC.

Yes, the alternative would be to have recursive queries, which I'm not a big fan of 😅

I could have a field referred_by which stores the id of the user who referred, whether it is a participant or a promoter (it can double as a check for if the user used a referral or not). However, for attributing points, I need the referred_by_promoter_id field as well to be able to avoid having to check who referred who recursively.

Yeah, exactly!

@AvilaAndre
Copy link
Contributor Author

Yes, but the migrations need to be 100% correct. We're dealing with a production system and we need to ensure that everything is perfect.

The good news is that the participant_info table does not have anything that participant_profile is missing. The bad news is that sqlite3 does not support dropping foreign keys, so, renaming the table and columns is proving to be a complicated task.

@limwa
Copy link
Member

limwa commented Feb 11, 2025

You can try on 1 migration to drop the foreign key constraint and on the next add it back
Alternatively, since the PR hasn't been merged yet and the models have the exact same information, you can simply use the other model and delete the old one, no migration needed

docker-compose.yaml Show resolved Hide resolved
website/app/middleware/referral_middleware.ts Outdated Show resolved Hide resolved
website/app/models/mixins/has_referral_link.ts Outdated Show resolved Hide resolved
website/app/models/company_representative_info.ts Outdated Show resolved Hide resolved
website/app/models/company_info.ts Outdated Show resolved Hide resolved
website/app/models/user.ts Outdated Show resolved Hide resolved
website/app/services/referral_service.ts Outdated Show resolved Hide resolved
website/package.json Outdated Show resolved Hide resolved
website/start/routes.ts Outdated Show resolved Hide resolved
@limwa limwa linked an issue Feb 18, 2025 that may be closed by this pull request
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Referral Link Generation & Association Implement Direct Referral System
3 participants