Class: Tablecheck::Blockages::Create
- Inherits:
-
Object
- Object
- Tablecheck::Blockages::Create
- Includes:
- DefaultErrorContainer, ApiHelpers
- Defined in:
- app/services/tablecheck/blockages/create.rb
Instance Attribute Summary collapse
-
#adult ⇒ Object
readonly
Returns the value of attribute adult.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#kids ⇒ Object
readonly
Returns the value of attribute kids.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
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_call, #channel, #find_tablecheck_vendor_application, #get_purpose, #headers, #parse_phone_number, #parse_user_or_guest_full_name, #parsed_vendor_name, #reservation_start_at, #send_error_availability_notification_to_staff
Constructor Details
#initialize(assignable_id, params = {}, assignable_type = :reservation) ⇒ Create
Returns a new instance of Create.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/tablecheck/blockages/create.rb', line 11 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[:date] @start_time = params[:start_time] @adult = params[:adult].to_i @kids = params[:kids].to_i else reservation = Reservation.find_by(id: assignable_id).decorate @restaurant = reservation.restaurant @date = reservation.date @start_time = reservation.start_time_format @adult = reservation.adult @kids = reservation.kids end end |
Instance Attribute Details
#adult ⇒ Object (readonly)
Returns the value of attribute adult.
9 10 11 |
# File 'app/services/tablecheck/blockages/create.rb', line 9 def adult @adult end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'app/services/tablecheck/blockages/create.rb', line 9 def date @date end |
#kids ⇒ Object (readonly)
Returns the value of attribute kids.
9 10 11 |
# File 'app/services/tablecheck/blockages/create.rb', line 9 def kids @kids end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
9 10 11 |
# File 'app/services/tablecheck/blockages/create.rb', line 9 def restaurant @restaurant end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
9 10 11 |
# File 'app/services/tablecheck/blockages/create.rb', line 9 def start_time @start_time end |
Instance Method Details
#execute ⇒ Object
31 32 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 70 |
# File 'app/services/tablecheck/blockages/create.rb', line 31 def execute errors.clear # Check if restaurant is using TableCheck inventory source inv_source = restaurant.inventory_source&.inv_source if inv_source.blank? || inv_source != ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME = "Restaurant #{restaurant.id} is not using TableCheck inventory source" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", restaurant_id: restaurant.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end shop_id = restaurant&.tablecheck_restaurant&.shop_id shop_slug = restaurant&.tablecheck_restaurant&.shop_slug if shop_id.blank? || shop_slug.blank? = "Invalid shop id: #{shop_id} or shop slug: #{shop_slug} of restaurant #{restaurant.id}" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", restaurant_id: restaurant.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Create blockage in Tablecheck result = create_blockage(blockage_params) unless result.success? = result. BUSINESS_LOGGER.error('TABLECHECK: Failed to create blockage', error_message: ) errors.add(:base, ) return ServiceResult.new errors: errors, message: end BUSINESS_LOGGER.info('TABLECHECK: Blockage created successfully', blockage: result.data) ServiceResult.new data: result.data end |