Class: MyMenu::Reservations::Update
- Inherits:
-
Object
- Object
- MyMenu::Reservations::Update
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers, ApiHelpers
- Defined in:
- app/services/my_menu/reservations/update.rb
Instance Attribute Summary collapse
-
#mymenu_reservation ⇒ Object
readonly
Returns the value of attribute mymenu_reservation.
-
#new_reservation ⇒ Object
readonly
Returns the value of attribute new_reservation.
-
#update_params ⇒ Object
readonly
Returns the value of attribute update_params.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(new_reservation, mm_reservation_id = nil, update_params = {}) ⇒ Update
constructor
A new instance of Update.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods included from ApiHelpers
#api_call, #channel, #find_mymenu_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(new_reservation, mm_reservation_id = nil, update_params = {}) ⇒ Update
Returns a new instance of Update.
13 14 15 16 17 18 |
# File 'app/services/my_menu/reservations/update.rb', line 13 def initialize(new_reservation, mm_reservation_id = nil, update_params = {}) @new_reservation = new_reservation.decorate @mymenu_reservation = (mm_reservation_id) @update_params = update_params BUSINESS_LOGGER.set_business_context({ reservation_id: new_reservation.id }) end |
Instance Attribute Details
#mymenu_reservation ⇒ Object (readonly)
Returns the value of attribute mymenu_reservation.
11 12 13 |
# File 'app/services/my_menu/reservations/update.rb', line 11 def @mymenu_reservation end |
#new_reservation ⇒ Object (readonly)
Returns the value of attribute new_reservation.
11 12 13 |
# File 'app/services/my_menu/reservations/update.rb', line 11 def new_reservation @new_reservation end |
#update_params ⇒ Object (readonly)
Returns the value of attribute update_params.
11 12 13 |
# File 'app/services/my_menu/reservations/update.rb', line 11 def update_params @update_params end |
Instance Method Details
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 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 |
# File 'app/services/my_menu/reservations/update.rb', line 20 def execute errors.clear = MyMenu::ErrorMessages::DEFAULT_ERROR # Check if reservation is blank if new_reservation.blank? = 'Reservation is blank' unless MyMenu::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}") end errors.add(:base, ) return ServiceResult.new errors: errors, message: end if .blank? = "MyMenu reservation not found for reservation #{new_reservation.id}" unless MyMenu::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}", reservation_id: new_reservation.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Update reservation in MyMenu reservation_params = build_update_params update_result = (reservation_params) unless update_result.success? = update_result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Update vendor reservation record if new ID returned result = (update_result.data['id']) if result.blank? = "Error updating reservation #{.reservation.id} in MymenuReservation" unless MyMenu::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}", reservation_id: .reservation.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end ServiceResult.new data: update_result.data end |