Class: SevenRooms::Blockages::Create
- Inherits:
-
Object
- Object
- SevenRooms::Blockages::Create
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers, ApiHelpers
- Defined in:
- app/services/seven_rooms/blockages/create.rb
Instance Attribute Summary collapse
-
#concierge_id ⇒ Object
readonly
Returns the value of attribute concierge_id.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#party_size ⇒ Object
readonly
Returns the value of attribute party_size.
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#venue_id ⇒ Object
readonly
Returns the value of attribute venue_id.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(assignable_id, params = {}, assignable_type = :reservation) ⇒ Create
constructor
A new instance of Create.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods included from ApiHelpers
#api_uri, #auth_headers, #common_headers, #find_seven_rooms_vendor_application, #parse_user_or_guest_full_name, #parsed_vendor_name, #send_error_availability_notification_to_staff, #sevenrooms_credit_card_error?, #standardize_or_default_phone
Constructor Details
#initialize(assignable_id, params = {}, assignable_type = :reservation) ⇒ Create
Returns a new instance of Create.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/seven_rooms/blockages/create.rb', line 13 def initialize(assignable_id, params = {}, assignable_type = :reservation) BUSINESS_LOGGER.set_business_context({ assignable_id: assignable_id, assignable_type: assignable_type }) BUSINESS_LOGGER.set_request_context(params) if assignable_type == :restaurant @restaurant = Restaurant.find_by(id: assignable_id) if assignable_id.present? @date = params.dig(:date) @start_time = params.dig(:start_time) @party_size = params.dig(:adult).to_i + params.dig(:kids).to_i else @reservation = Reservation.find_by(id: assignable_id).decorate @restaurant = reservation.restaurant @date = reservation.date @start_time = reservation.start_time_format @party_size = reservation.party_size end @concierge_id = AdminSetting.seven_rooms_concierge_id.to_s @venue_id = @restaurant&.seven_rooms_restaurant&.venue_id.to_s end |
Instance Attribute Details
#concierge_id ⇒ Object (readonly)
Returns the value of attribute concierge_id.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def concierge_id @concierge_id end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def date @date end |
#party_size ⇒ Object (readonly)
Returns the value of attribute party_size.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def party_size @party_size end |
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def reservation @reservation end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def restaurant @restaurant end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def start_time @start_time end |
#venue_id ⇒ Object (readonly)
Returns the value of attribute venue_id.
10 11 12 |
# File 'app/services/seven_rooms/blockages/create.rb', line 10 def venue_id @venue_id end |
Instance Method Details
#execute ⇒ Object
33 34 35 36 37 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 65 66 67 68 69 |
# File 'app/services/seven_rooms/blockages/create.rb', line 33 def execute errors.clear # Check if restaurant is using SevenRoom inventory source inv_source = restaurant.inventory_source&.inv_source if inv_source.blank? || inv_source != ApiVendorV1::Constants::SEVEN_ROOMS_INV_SOURCE_NAME = "Restaurant #{restaurant.id} is not using SevenRoom inventory source" unless SevenRooms::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("SEVENROOM: #{self.class} #{}", restaurant_id: restaurant.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end if venue_id.blank? = "Invalid venue id: #{venue_id} of restaurant #{restaurant.id}" unless SevenRooms::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("SEVENROOM: #{self.class} #{}", restaurant_id: restaurant.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Create blockage in SevenRooms result = create_blockage unless result.success? = result. BUSINESS_LOGGER.error('SEVENROOM: Failed to create blockage', error_message: ) errors.add(:base, ) return ServiceResult.new errors: errors, message: end BUSINESS_LOGGER.info('SEVENROOM: Blockage created successfully', blockage: result.data) ServiceResult.new data: result.data end |