Class: Api::Vendor::V1::Concerns::UpdateReservation

Inherits:
PackageBooking::Users::Update show all
Defined in:
app/controllers/api/vendor/v1/concerns/update_reservation.rb

Constant Summary

Constants inherited from Agents::Base

Agents::Base::WORKER_DELAY_TIME

Instance Attribute Summary

Attributes inherited from PackageBooking::Users::Update

#package, #vendor_reservation_params

Attributes inherited from Agents::Base

#audit_comment, #errors, #executor, #force_update, #owner, #reservation, #reservation_params, #restaurant, #user, #vendor_booking_id

Instance Method Summary collapse

Methods inherited from PackageBooking::Users::Update

#change_personal_data_or_special_request_only?, #decrease_seat_only?, #has_change_package_attr?, #initialize, #inventory_available?, #non_prepaid_packages?, #nonprepaid_to_prepaid_switch?, #origin_change_personal_data_or_special_request_only?, #origin_decrease_seat_only?, #origin_inventory_available?, #origin_primary_attr_changed?, #prepaid_packages?, #validate_min_spending_tier

Methods included from PackageBooking::CustomPackagePricing

#apply_custom_package_pricing_feature

Methods included from PackageBooking::Components::ViewDecorator

#origin_selected_packages, #reservation_attributes, #selected_packages, #state

Methods inherited from Agents::ModifyBookingForUser

#execute, #execute!, #initialize

Methods included from RefundGuaranteeHelper

#calculate_min_refund_hours, #calculate_refundable_until_time

Methods included from Reservations::CheckSeatDecreased

#decrease_seat_only?

Methods included from Reservations::CheckSeatIncreased

#change_packages?, #increase_seat_only?

Methods inherited from Agents::Update

#after_initialize, #execute!, #initialize, #update_booking, #update_booking!

Methods included from Agents::ErrorType

#fatal_error?, #inventory_error?, #normal_error?, #overwrite_error_type!

Methods inherited from Agents::Base

#error_message, #hotline, #inventory_available?, #save_reservation!, #status=

Methods included from Agents::SharedJobs

#give_campaign_reward, #send_rating_email

Constructor Details

This class inherits a constructor from PackageBooking::Users::Update

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Agents::Base

Instance Method Details

#primary_attr_changed?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
# File 'app/controllers/api/vendor/v1/concerns/update_reservation.rb', line 6

def primary_attr_changed?
  %I[date start_time end_time party_size adult kids phone name email special_request].each do |attr|
    return true if reservation.changes.include?(attr)
  end

  return true if vendor_reservation_params&.key?(:reference_id)

  false
end

#sync_updated_reservations!(updated_reservation) ⇒ Object

Trigger reservation summary sync after successful vendor reservation update



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/api/vendor/v1/concerns/update_reservation.rb', line 44

def sync_updated_reservations!(updated_reservation)
  # Use delayed async execution since vendor reservations are created_by :user
  updated_reservation.trigger_summary_sync

  # Sync old reservation if this was a modify booking
  if updated_reservation.old_reservation_id.present?
    old_reservation = Reservation.find_by(id: updated_reservation.old_reservation_id)
    old_reservation&.trigger_summary_sync
  end
rescue StandardError => e
  APMErrorHandler.report('Failed to sync updated reservations', {
                           updated_reservation_id: updated_reservation&.id,
                           old_reservation_id: updated_reservation&.old_reservation_id,
                           error_message: e.message,
                           exception: e,
                         })
end

#update_vendor_payment!(old_reservation_id, new_reservation_id, vendor_id) ⇒ Object

Move the vendor payment from old reservation to new reservation



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/api/vendor/v1/concerns/update_reservation.rb', line 30

def update_vendor_payment!(old_reservation_id, new_reservation_id, vendor_id)
  vendor_payment = VendorPayment.find_by(reservation_id: old_reservation_id, vendor_id: vendor_id)
  if vendor_payment.present?
    vendor_payment.update!(reservation_id: new_reservation_id)
  else
    APMErrorHandler.report("Vendor payment not found for reservation_id: #{old_reservation_id}", {
      old_reservation_id: old_reservation_id,
      vendor_id: vendor_id,
      new_reservation_id: new_reservation_id,
    })
  end
end

#update_vendor_reservation!(vendor_reservation_id, new_reservation_id) ⇒ Object

Update vendor reservation and replace the old reservation_id with the new reservation_id, but the vendor_reservations.id is not changed



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/api/vendor/v1/concerns/update_reservation.rb', line 18

def update_vendor_reservation!(vendor_reservation_id, new_reservation_id)
  vendor_reservation_params[:reservation_id] = new_reservation_id

  vendor_reservation = VendorReservation.find(vendor_reservation_id)
  vendor_reservation.update!(vendor_reservation_params)

  Reservation.
    includes(:vendor_reservation).
    where(vendor_reservations: { id: vendor_reservation_id }, active: true).first!
end