Created
September 7, 2017 03:18
-
-
Save staycreativedesign/8762ef18128e77838c02de4d8d06058a to your computer and use it in GitHub Desktop.
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
class CreatesPoint | |
POINTS = { 'new_user' => 1, | |
'trial_to_paid' => 2, | |
'attended_event' => 1 | |
} | |
def initialize(user_id,point) | |
@user_id = user_id | |
@point = POINTS[point] | |
end | |
def run! | |
create_point | |
end | |
private | |
def create_point | |
user = User.find_by(referral_code: @user_id) | |
user.points += @point | |
user.save | |
end | |
end |
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
def create_user | |
@user = User.new(user_params) | |
if @user.save | |
create_user_account | |
CreatesPoint.new(@user.referrer, 'new_user').run! | |
true | |
else | |
false | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment