Class: Bistrochat::Reservations::Update
- Inherits:
-
Object
- Object
- Bistrochat::Reservations::Update
- Includes:
- ApiHelpers, DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/bistrochat/reservations/update.rb
Instance Attribute Summary collapse
-
#bistrochat_reservation ⇒ Object
readonly
Returns the value of attribute bistrochat_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(reservation, tc_reservation_id, update_params) ⇒ Update
constructor
A new instance of Update.
- #update_reservation_params ⇒ Object
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods included from ApiHelpers
#api_call, #channel, #find_bistrochat_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(reservation, tc_reservation_id, update_params) ⇒ Update
Returns a new instance of Update.
13 14 15 16 17 18 19 |
# File 'app/services/bistrochat/reservations/update.rb', line 13 def initialize(reservation, tc_reservation_id, update_params) @new_reservation = reservation.decorate @bistrochat_reservation = find_bistrochat_reservation(tc_reservation_id) validate_update_params(update_params) @update_params = update_params BUSINESS_LOGGER.set_business_context({ reservation_id: new_reservation.id }) end |
Instance Attribute Details
#bistrochat_reservation ⇒ Object (readonly)
Returns the value of attribute bistrochat_reservation.
11 12 13 |
# File 'app/services/bistrochat/reservations/update.rb', line 11 def bistrochat_reservation @bistrochat_reservation end |
#new_reservation ⇒ Object (readonly)
Returns the value of attribute new_reservation.
11 12 13 |
# File 'app/services/bistrochat/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/bistrochat/reservations/update.rb', line 11 def update_params @update_params end |
Instance Method Details
#execute ⇒ Object
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 70 |
# File 'app/services/bistrochat/reservations/update.rb', line 21 def execute errors.clear = Bistrochat::ErrorMessages::DEFAULT_ERROR if new_reservation.blank? = 'Reservation not found' unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}") end BUSINESS_LOGGER.error("#{self.class} #{}") errors.add(:base, ) return ServiceResult.new errors: errors, message: end if bistrochat_reservation.blank? = "VendorReservation for reservation #{new_reservation.id} not found" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}", reservation_id: new_reservation.id) end BUSINESS_LOGGER.error("#{self.class} #{}", reservation_id: new_reservation.id) errors.add(:base, ) return ServiceResult.new errors: errors, message: end update_result = update_reservation(update_reservation_params) unless update_result.success? = update_result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end result = update_old_bistrochat_reservation(update_result.data['id']) if result.blank? = "Error updating reservation #{bistrochat_reservation.reservation.id} in BistrochatReservation" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}", reservation_id: bistrochat_reservation.reservation.id) end BUSINESS_LOGGER.error("#{self.class} #{}", reservation_id: bistrochat_reservation.reservation.id) errors.add(:base, ) return ServiceResult.new errors: errors, message: end ServiceResult.new data: result end |
#update_reservation_params ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/services/bistrochat/reservations/update.rb', line 73 def update_reservation_params notes = VendorsService::GenerateMemoService.new(new_reservation).execute { pax_adult: update_params[:pax_adult], pax_child: update_params[:pax_child], pax: update_params[:pax], start_at: update_params[:start_at], memo2: notes, purpose: get_purpose(update_params[:occasion].to_s), ref: new_reservation.id, } end |