Class: Agents::ModifyForOwner
- Defined in:
- app/my_lib/agents/modify_for_owner.rb
Overview
This builder will cancel reservation and make new one
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#new_reservation ⇒ Object
Returns the value of attribute new_reservation.
-
#new_reservation_params ⇒ Object
Returns the value of attribute new_reservation_params.
-
#old_reservation ⇒ Object
Returns the value of attribute old_reservation.
Attributes inherited from Base
#audit_comment, #errors, #executor, #force_update, #owner, #reservation, #reservation_params, #restaurant, #user, #vendor_booking_id
Instance Method Summary collapse
- #execute ⇒ Object
- #execute! ⇒ Object
-
#initialize(reservation, new_reservation_params) ⇒ ModifyForOwner
constructor
A new instance of ModifyForOwner.
- #send_notification ⇒ Object
Methods inherited from Update
#after_initialize, #update_booking, #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
#initialize(reservation, new_reservation_params) ⇒ ModifyForOwner
Returns a new instance of ModifyForOwner.
13 14 15 16 17 18 19 20 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 13 def initialize(reservation, new_reservation_params) @old_reservation = if reservation.is_a?(::Reservation) reservation else ::Reservation.find(reservation) end @new_reservation_params = new_reservation_params.merge(modified_by: :owner) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Agents::Base
Instance Attribute Details
#new_reservation ⇒ Object
Returns the value of attribute new_reservation.
11 12 13 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 11 def new_reservation @new_reservation end |
#new_reservation_params ⇒ Object
Returns the value of attribute new_reservation_params.
11 12 13 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 11 def new_reservation_params @new_reservation_params end |
#old_reservation ⇒ Object
Returns the value of attribute old_reservation.
11 12 13 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 11 def old_reservation @old_reservation end |
Instance Method Details
#execute ⇒ Object
35 36 37 38 39 40 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 35 def execute execute! rescue InvalidReservation, ActiveRecord::ActiveRecordError => e HH_LOGGER.info e false end |
#execute! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 22 def execute! modify! @old_reservation.touch @reservation = new_reservation sync_reservation_summaries(@old_reservation, @new_reservation) send_notification Netcore::EventWorker.perform_in(Netcore::EventWorker::DELAY, :reservation_event, @old_reservation.id) true end |
#send_notification ⇒ Object
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 |
# File 'app/my_lib/agents/modify_for_owner.rb', line 42 def send_notification if new_reservation.private_channel? # ack is always true for private channel NotificationService::Email.new(receiver: :user, reservation: new_reservation).send_modification_email NotificationService::Sms.new(phones: owner.phone, reservation: old_reservation).send_cancel_msg NotificationService::Sms.new(phones: new_reservation.phone, reservation: new_reservation).send_confirmation_msg_to_user NotificationService::Sms.new(phones: owner.phone, reservation: new_reservation).send_confirmation_msg_to_restaurant else NotificationService::Email.new(receiver: :user, reservation: new_reservation).send_modification_email NotificationService::Sms.new(phones: owner.phone, reservation: old_reservation).send_cancel_msg NotificationService::Email.new(receiver: :owner, reservation: old_reservation).send_cancel_email if new_reservation.ack? # OWNER NotificationService::Email.new(receiver: :owner, reservation: new_reservation).send_confirmation_email NotificationService::Sms.new(phones: owner.phone, reservation: new_reservation).send_confirmation_msg_to_restaurant # STAFF NotificationService::Email.new(receiver: :staff, reservation: new_reservation).send_confirmation_email else # STAFF NotificationService::Sms.new(phones: AdminSetting.hotline_for_no_ack, reservation: new_reservation).send_pending_msg_to_hh # OWNER NotificationService::Sms.new(phones: owner.phone, reservation: new_reservation).send_pending_msg_to_restaurant end end end |