Class: Agents::UpdateForOwner
- Defined in:
- app/my_lib/agents/update_for_owner.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#audit_comment, #errors, #executor, #force_update, #owner, #reservation, #reservation_params, #restaurant, #user, #vendor_booking_id
Instance Method Summary collapse
Methods inherited from Update
#execute!, #initialize, #update_booking
Methods included from ErrorType
#fatal_error?, #inventory_error?, #normal_error?, #overwrite_error_type!
Methods inherited from Base
#error_message, #hotline, #inventory_available?, #save_reservation!, #status=
Methods included from SharedJobs
#give_campaign_reward, #send_rating_email
Constructor Details
This class inherits a constructor from Agents::Update
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Agents::Base
Instance Method Details
#after_initialize ⇒ Object
11 12 13 14 |
# File 'app/my_lib/agents/update_for_owner.rb', line 11 def after_initialize reservation.audit_comment = 'Adapter updating class by owner' reservation.modified_by = :owner end |
#update_booking! ⇒ Object
16 17 18 19 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/my_lib/agents/update_for_owner.rb', line 16 def update_booking! result = false ActiveRecord::Base.transaction do validate_owner_parameters! check_no_show! if confirmed? confirmed = Confirm.new(reservation, reservation_params) updated = confirmed.update_booking @errors = confirmed.errors return updated end if cancelled? service = CancelReservationService.new(reservation.id, :owner) service.cancel_reason = 'cancel reason is not implemented yet' updated = service.execute @errors = service.errors return updated end if arrived? instance = OwnerUpdateArrived.new(reservation) result = instance.update_booking @errors = instance.errors return result end if no_show_changed? && reservation.changes[:no_show][1] no_show = UpdateAsNoShow.new(reservation) updated = no_show.update_booking @errors = no_show.errors return updated end return true unless reservation.changed? # Ignore note if the changes coming from TableCheck or SevenRooms webhook callback if reservation.note.to_s == 'from_tablecheck_webhook' || reservation.note.to_s == 'from_seven_rooms_webhook' reservation.note = Reservation.fetch(reservation.id).note end save_reservation!(validate: false) if reservation.package.present? = HhPackage::ReservationPackages::Metadata.from_reservation(reservation) reservation.property.assign_attributes(package: .generate) reservation.property.save! end reservation.save(:sneaky) if reservation.changes.present? unless @force_update update_tc_result = update_tablecheck_reservation unless update_tc_result.success? error_msg = Tablecheck::ErrorMessages.('owner', update_tc_result.) errors.add(:base, error_msg) raise Agents::InvalidReservation, error_msg end update_sr_result = update_seven_rooms_reservation unless update_sr_result.success? error_msg = SevenRooms::ErrorMessages.('owner', update_sr_result.) errors.add(:base, error_msg) raise Agents::InvalidReservation, error_msg end update_weeloy_result = update_weeloy_reservation unless update_weeloy_result.success? error_msg = Weeloy::ErrorMessages.('owner', update_weeloy_result.) errors.add(:base, error_msg) raise Agents::InvalidReservation, error_msg end update_bistrochat_result = update_bistrochat_reservation unless update_bistrochat_result.success? errors.add(:base, Bistrochat::ErrorMessages.('owner', update_bistrochat_result.)) raise Agents::InvalidReservation end = unless .success? errors.add(:base, MyMenu::ErrorMessages.('owner', .)) raise Agents::InvalidReservation end end result = true end if reservation.user_id.present? if reservation.id.blank? APMErrorHandler.report('Nil reservation id detected before enqueuing reward workers') else LoyaltyPrograms::TierQualificationWorker.perform_async(reservation.id) end end Netcore::EventWorker.perform_in(Netcore::EventWorker::DELAY, :reservation_event, reservation.id) give_rewards(reservation) result end |