Class: RewardCpt::Operations::GivingOperation

Inherits:
Trailblazer::Operation
  • Object
show all
Extended by:
Contract::DSL
Defined in:
app/concepts/reward_cpt/operations/giving_operation.rb

Overview

Operation class to check whether given code is a another user referral code

Instance Method Summary collapse

Instance Method Details

#find_user!(options) ⇒ Object



21
22
23
24
25
# File 'app/concepts/reward_cpt/operations/giving_operation.rb', line 21

def find_user!(options, *)
  options['user'] = User.find options['params']['user_id']
rescue ActiveRecord::RecordNotFound
  false
end

#give_reward!(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/concepts/reward_cpt/operations/giving_operation.rb', line 27

def give_reward!(options, *)
  user = options['user']
  reward = Reward.new user_id: user.id,
                      points_total: options['params']['amount'],
                      points_pending: 0,
                      description: options['params']['description'],
                      redeemed: false,
                      country_id: user.country_id
  reward.save
end