Module: LoyaltyProgram::SpecialBenefits::Campaign

Included in:
GiveReservationRewardWorker, Benefits::DineInPoints
Defined in:
app/my_lib/loyalty_program/special_benefits/campaign.rb

Overview

This module is intended to verify whether a loyalty program's special campaign qualifies for earning multiple points.

Instance Method Summary collapse

Instance Method Details

#eligible_to_double_point?(reservation) ⇒ Boolean

Check if the user associated with a reservation is eligible for double points

Parameters:

  • reservation (Object)

    the reservation object

Returns:

  • (Boolean)

    true if the user is eligible for double points, false otherwise



8
9
10
11
12
13
14
15
16
17
# File 'app/my_lib/loyalty_program/special_benefits/campaign.rb', line 8

def eligible_to_double_point?(reservation)
  return false if reservation.user.blank?

  restaurant = reservation.restaurant
  special_tag_id = AdminSetting.double_point_restaurant_tag_id
  new_restaurant_tag = RestaurantTag.find_by(id: special_tag_id)
  return false if new_restaurant_tag.blank?

  restaurant.restaurant_tag_ids.include?(new_restaurant_tag.id)
end

#eligible_to_triple_point?(reservation) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/my_lib/loyalty_program/special_benefits/campaign.rb', line 19

def eligible_to_triple_point?(reservation)
  return false unless reservation.is_a?(Reservation)
  return false if reservation.user.blank?
  return false if reservation.package.blank?

  return false unless reservation.package_obj.type_short == 'ayce'

  dining_date = reservation.date
  date_setting = AdminSetting.triple_point_date_range

  # Split the date_setting string into start_date and end_date strings
  start_date, end_date = date_setting.split('-')

  # Convert start_date and end_date strings to Ruby Date objects
  start_date = Date.strptime(start_date, '%d/%m/%Y')
  end_date = Date.strptime(end_date, '%d/%m/%Y')

  dining_date.between?(start_date, end_date)
end