Class: Agents::OwnerUpdateArrived

Inherits:
Update show all
Defined in:
app/my_lib/agents/owner_update_arrived.rb

Constant Summary

Constants inherited from Base

Base::WORKER_DELAY_TIME

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_initializeObject



9
10
11
# File 'app/my_lib/agents/owner_update_arrived.rb', line 9

def after_initialize
  reservation.audit_comment = 'Marked as arrived by owner'
end

#update_booking!Object



13
14
15
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
# File 'app/my_lib/agents/owner_update_arrived.rb', line 13

def update_booking!
  reservation.mark_as_arrived!
  reservation.mark_voucher_as_active!
  reservation.save! validate: false

  # Trigger sync for owner arrival update (immediate for owner operations)
  reservation.trigger_immediate_sync

  BUSINESS_LOGGER.set_business_context({ reservation_id: reservation.id })

  Netcore::EventWorker.perform_in(Netcore::EventWorker::DELAY, :reservation_event, reservation.id)
  # we update normal reservation every midnight for 'arrived' reservation
  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

  if reservation.aoa_reservation.present? && reservation.aoa_channel?
    BUSINESS_LOGGER.info("#{self.class}: Aoa::WebhookWorker called from update_booking! method with status :arrived")
    Aoa::WebhookWorker.default_perform_async(reservation.id, :arrived)
  end

  if reservation.by_marketplace?
    vendor_name = reservation.vendor_reservation.oauth_application.name
    status = ApiVendorV1::Constants::CONFIRM

    case vendor_name
    when ApiVendorV1::Constants::OPEN_RICE_VENDOR_NAME
      BUSINESS_LOGGER.info(
        "#{self.class}: Vendors::OpenRice::WebhookWorker called from update_booking! method with status #{status}", status: status
      )
      Vendors::OpenRice::WebhookWorker.perform_async(reservation.id.to_s,
                                                     reservation.vendor_reservation.id.to_s,
                                                     status)
    when ApiVendorV1::Constants::TAG_THAI_VENDOR_NAME
      BUSINESS_LOGGER.info(
        "#{self.class}: Vendors::TagThai::WebhookWorker called from update_booking! method with status #{status}", status: status
      )
      Vendors::TagThai::WebhookWorker.perform_async(reservation.id, status)
    when ApiVendorV1::Constants::GOOGLE_RESERVE_VENDOR_NAME
    # No need to update Google Reserve status
    else
      APMErrorHandler.report("Invalid vendor name: #{vendor_name}")
    end
  end

  true
end