Module: LoyaltyProgram::Benefits::ReviewPoints

Included in:
GiveReservationRewardWorker
Defined in:
app/my_lib/loyalty_program/benefits/review_points.rb

Instance Method Summary collapse

Instance Method Details

#calc_amount(review) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/my_lib/loyalty_program/benefits/review_points.rb', line 16

def calc_amount(review)
  country_code = review.reservation.restaurant.country.alpha3
  user_loyalty_data = user_loyalty(review.reservation)

  benefit_key_base = review.review_photos_count >= 3 ? 'review_with_photos' : 'review_without_photos'
  benefit_key = if country_code.present? && country_code == ApiV5::Constants::COUNTRY_CODE_SG
                  "#{benefit_key_base}_sg"
                elsif country_code.present? && country_code == ApiV5::Constants::COUNTRY_CODE_MY
                  "#{benefit_key_base}_my"
                else
                  "#{benefit_key_base}_th"
                end

  case review.state.to_f
  when ::ReviewReservationDecorator::SECOND_STEP, ::ReviewReservationDecorator::SECOND_HALF_STEP, ::ReviewReservationDecorator::THIRD_STEP
    user_loyalty_data.benefit_value(benefit_key, cast: :to_i)
  else
    0
  end
end

#find_description(review) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/my_lib/loyalty_program/benefits/review_points.rb', line 2

def find_description(review)
  case review.state.to_f
  when ReviewReservationDecorator::FIRST_STEP
    nil
  when ReviewReservationDecorator::SECOND_STEP, ReviewReservationDecorator::SECOND_HALF_STEP, ReviewReservationDecorator::THIRD_STEP
    return nil if review.reservation.user_id.blank?

    'Create reservation review'
  else
    BUSINESS_LOGGER.error('unknown review state', review_id: review.id)
    nil
  end
end

#user_loyalty(reservation) ⇒ Object



37
38
39
40
41
# File 'app/my_lib/loyalty_program/benefits/review_points.rb', line 37

def user_loyalty(reservation)
  return nil if reservation.user.blank?

  reservation.user.user_loyalty
end