Module: Agents::SharedJobs

Included in:
Base
Defined in:
app/my_lib/agents/shared_jobs.rb

Instance Method Summary collapse

Instance Method Details

#give_campaign_rewardObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/my_lib/agents/shared_jobs.rb', line 6

def give_campaign_reward
  return unless user.present?

  # skip if restaurant is not eligible for rewards
  return unless restaurant.eligible_for_rewards?

  sb = ::SpecialBonus.find_by campaign_date: reservation.date, restaurant_id: restaurant.id
  return unless sb.present?

  if sb.point_multiplier.nil?
    sb.point_multiplier = 1
  else
    sb.point_multiplier += 1
  end

  reward = Reward.new user_id: user.id, points_total: sb.point_base,
                      points_pending: sb.point_base, description: 'Restaurant Special Day Campaign',
                      redeemed: false, reservation_id: reservation.id,
                      country_id: reservation.restaurant.country_id
  if reward.save!
    sb.save!
  else
    errors.add(:base, reward.errors.full_messages.to_sentence)
  end
end

#send_rating_emailObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/my_lib/agents/shared_jobs.rb', line 32

def send_rating_email
  return if reservation.email.to_s.strip == 'dummy@hungryhub.com' || reservation.email.blank?

  if reservation.id.blank?
    APMErrorHandler.report('Nil reservation id detected before enqueuing rating reservation worker')
  else
    Workers::Reservations::RatingReservationWorker.perform_at(
      (reservation.reservation_time + ::Reservation::RATING_DELAY_TIME), reservation.id
    )
  end
end