Class: ReservationService::Vendor

Inherits:
Object
  • Object
show all
Defined in:
app/services/reservation_service/vendor.rb

Overview

The ReservationService::Vendor class handles vendor-related operations for reservations. It provides functionality to find partner vendors, build reservation vendor attributes, and manage vendor user information.

Example usage:

vendor = ReservationService::Vendor.new('vendor_name')
partner_vendor = vendor.partner_vendor
vendor_attrs = vendor.reservation_vendor_attributes

# ... perform operations with partner_vendor and vendor_attrs ...

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_name, web_v2_host = nil) ⇒ Vendor

Returns a new instance of Vendor.

Parameters:

  • vendor_name (String)

    The vendor parameter.



17
18
19
20
21
# File 'app/services/reservation_service/vendor.rb', line 17

def initialize(vendor_name, web_v2_host = nil)
  @vendor_name = vendor_name
  @web_v2_host = web_v2_host
  @guest_user_attrs = guest_user_attrs
end

Instance Attribute Details

#guest_user_attrsObject

Returns the value of attribute guest_user_attrs.



14
15
16
# File 'app/services/reservation_service/vendor.rb', line 14

def guest_user_attrs
  @guest_user_attrs
end

#vendorObject

Returns the value of attribute vendor.



14
15
16
# File 'app/services/reservation_service/vendor.rb', line 14

def vendor
  @vendor
end

#vendor_nameObject

Returns the value of attribute vendor_name.



14
15
16
# File 'app/services/reservation_service/vendor.rb', line 14

def vendor_name
  @vendor_name
end

#web_v2_hostObject

Returns the value of attribute web_v2_host.



14
15
16
# File 'app/services/reservation_service/vendor.rb', line 14

def web_v2_host
  @web_v2_host
end

Instance Method Details

#partner_vendorDoorkeeper::Application? Also known as: partner_vendor?

Finds the partner vendor based on the vendor parameter.

Returns:

  • (Doorkeeper::Application, nil)

    The partner vendor or nil if not found.



26
27
28
29
30
31
# File 'app/services/reservation_service/vendor.rb', line 26

def partner_vendor
  return if vendor_name.blank?

  @vendor = Doorkeeper::Application.where('name LIKE ? AND name LIKE ?', 'HH x %', "%#{vendor_name}%").first
  vendor
end

#reservation_vendor_attributesHash

Builds the attributes for the reservation's vendor.

Returns:

  • (Hash)

    The vendor attributes for reservation.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/services/reservation_service/vendor.rb', line 38

def reservation_vendor_attributes
  return {} if partner_vendor.blank?
  return {} if guest_user_attrs.blank?

  vendor_attrs = { vendor_id: partner_vendor.id }

  vuser_attrs = vendor_user_attributes
  rwg_token = nil
  if partner_vendor&.name == ApiVendorV1::Constants::GOOGLE_RESERVE_VENDOR_NAME && guest_user_attrs[:rwg_token].present?
    rwg_token = guest_user_attrs[:rwg_token]
  end

  if vendor_user.present?
    vu = vendor_user
    vu.rwg_token = rwg_token if rwg_token
    vendor_attrs[:vendor_user] = vu
  else
    vendor_attrs[:vendor_user_attributes] = vuser_attrs
    vendor_attrs[:vendor_user_attributes][:rwg_token] = rwg_token if rwg_token
  end

  if web_v2_host.present?
    vendor_attrs[:web_v2_host] = web_v2_host
  end

  vendor_attrs
end

#vendor_reservations_attributes_from_admin(reservation_params) ⇒ Object



66
67
68
69
70
# File 'app/services/reservation_service/vendor.rb', line 66

def vendor_reservations_attributes_from_admin(reservation_params)
  vendor_booking_id = reservation_params[:vendor_booking_id].presence

  { vendor_id: partner_vendor.id, reference_id: vendor_booking_id }
end