Module: Api::Vendor::V1::Concerns::ReservationUtils

Overview

typed: ignore frozen_string_literal: true

Constant Summary collapse

HH_RESERVATION_INVENTORY_ERRORS =
[
  'Restaurant is closed',
  'Package is not available at selected time',
  I18n.t('inventory.seat_is_full'),
  I18n.t('inventory.not_available'),
].freeze

Instance Method Summary collapse

Instance Method Details

#calculate_package_qty(rest_pack, adult, kids) ⇒ Integer

need to adjust package qty if vendor do not let customers select package qty for per_pack type packages such vendor list is saved in ::Channel.adjust_package_qty_for_vendor?

Parameters:

  • rest_pack (RestPack)

    The rest pack object.

  • adult (Integer)

    The number of adults.

  • kids (Integer)

    The number of kids.

Returns:

  • (Integer)

    The calculated package quantity.



24
25
26
27
28
29
30
31
# File 'app/controllers/api/vendor/v1/concerns/reservation_utils.rb', line 24

def calculate_package_qty(rest_pack, adult, kids)
  total_count = 1 # for per_person packages, we send package qty as 1 in reservation params
  if rest_pack&.package&.dynamic_price_pricing_model&.to_sym == :per_pack
    per_pack_qty = rest_pack&.package&.dynamic_pricings&.first&.per_pack
    total_count = (adult.to_i + kids.to_i).fdiv(per_pack_qty).ceil if per_pack_qty.present?
  end
  total_count
end

#calculate_pax_qty(restaurant_package_id, adult, kids) ⇒ Array<Integer>

need to adjust adult/kids qty to block restaurant inventory, since vendor lets customer selects package qty only such vendor list is saved in ::Channel.adjust_pax_to_max_per_pack_qty?

Parameters:

  • restaurant_package_id (Integer)

    the ID of the restaurant package to look up

  • adult (Integer)

    initial count of adults

  • kids (Integer)

    initial count of kids

Returns:

  • (Array<Integer>)

    the updated counts of adults and kids



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/api/vendor/v1/concerns/reservation_utils.rb', line 40

def calculate_pax_qty(restaurant_package_id, adult, kids)
  rest_pack = HhPackage::RestaurantPackage.find_by(id: restaurant_package_id)

  if rest_pack&.package&.dynamic_price_pricing_model&.to_sym == :per_pack
    per_pack_qty = rest_pack&.package&.dynamic_pricings&.first&.per_pack

    if per_pack_qty
      adult = per_pack_qty
      kids = 0
    end
  end

  [adult.to_i, kids.to_i]
end

#hh_reservation_inventory_errorsObject



55
56
57
# File 'app/controllers/api/vendor/v1/concerns/reservation_utils.rb', line 55

def hh_reservation_inventory_errors
  HH_RESERVATION_INVENTORY_ERRORS
end