Class: GiveTicketRewardWorker

Inherits:
ApplicationWorker show all
Includes:
Modules::TicketTransactions::RewardPoints
Defined in:
app/workers/give_ticket_reward_worker.rb

Overview

operation class to give reward to user based on ticket_transaction id

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Constructor Details

#initializeGiveTicketRewardWorker

Returns a new instance of GiveTicketRewardWorker.



10
11
12
13
# File 'app/workers/give_ticket_reward_worker.rb', line 10

def initialize
  @description = []
  @points_total = 0
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'app/workers/give_ticket_reward_worker.rb', line 8

def description
  @description
end

#points_totalObject

Returns the value of attribute points_total.



8
9
10
# File 'app/workers/give_ticket_reward_worker.rb', line 8

def points_total
  @points_total
end

#ticket_transactionObject

Returns the value of attribute ticket_transaction.



8
9
10
# File 'app/workers/give_ticket_reward_worker.rb', line 8

def ticket_transaction
  @ticket_transaction
end

Instance Method Details

#perform(ticket_transaction_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/workers/give_ticket_reward_worker.rb', line 15

def perform(ticket_transaction_id)
  @ticket_transaction = TicketTransaction.find(ticket_transaction_id)

  # Skip if ticket transaction is created from website
  return false if ticket_transaction.created_from_website?

  # Skip if restaurant is not eligible for rewards
  return false unless ticket_transaction.restaurant.eligible_for_rewards?

  return false if ticket_transaction.user.nil? || !ticket_transaction.active || ticket_transaction.paid_charges.blank?

  calc_reward_for_creating_ticket_transaction

  reward.attributes = {
    restaurant_id: ticket_transaction.restaurant_id,
    points_total: points_total,
    points_pending: 0,
    description: description.compact.join(' - '),
    user_id: ticket_transaction.user_id,
    redeemed: false,
    country_id: ticket_transaction.restaurant.country_id,
  }
  reward.save!

  true
end