Class: Agents::UpdateBookingStatusForUser

Inherits:
Update
  • Object
show all
Defined in:
app/my_lib/agents/update_booking_status_for_user.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

#after_initialize, #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

#customer_did_not_show_upObject



88
89
90
91
92
93
94
95
96
97
98
# File 'app/my_lib/agents/update_booking_status_for_user.rb', line 88

def customer_did_not_show_up
  message = <<~BODY
    Customer did not go to the restaurant
    Please verify this request
    Reservation ID = #{reservation.id}
    Customer ID = #{reservation.user_id.presence || '- (manual)'}
    Restaurant ID = #{reservation.restaurant.id}
    Restaurant Name = #{reservation.restaurant.name}
  BODY
  UserMailer.notify_support('Customer did not show up', message).deliver_later!
end

#customer_dispute_no_showObject



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
# File 'app/my_lib/agents/update_booking_status_for_user.rb', line 58

def customer_dispute_no_show
  restaurant = reservation.restaurant
  reservation.audit_comment = 'customer dispute no show'
  reservation.dont_mark_as_no_show!
  reservation.save!
  message = <<~BODY
    เรียน/Dear ทีม/Team #{restaurant.name}
    <br>
    <br>
    ชื่อลูกค้า/Customer Name : #{reservation.name}<br>
    เบอร์โทรลูกค้า/Customer Mobile: #{reservation.phone}<br>
    อีเมลลูกค้า/Customer Email: #{reservation.email}<br>
    เลขที่การจอง/ Booking ID : #{reservation.id}<br>
    วันที่จอง/Booking Date : #{reservation.date}<br>
    เวลาที่จอง/ Booking Time : #{reservation.start_time_format}<br>
    <br>
    <br>
    ลูกค้าได้มีการส่งคำร้องโต้แย้งปฏิเสธสถานะ 'No Show' ซึ่งขณะนี้สถานะของลูกค้าจะถูกเปลี่ยนเป็น 'Arrived' โดยอัตโนมัติ หากร้านอาหารมีหลักฐานยืนยันว่าลูกค้าไม่ได้มาทานจริง<br>
    กรุณาติดต่อ Hungry Hub ที่ https://line.me/R/ti/p/%40zmr6478h<br>
    หรือโทร 081 939 1600<br>
    <br>
    <br>
    Has disputed the “No Show” Status. The customer has indicated he/she did in-fact dine at the restaurant. Please note that the customer status has been changed to "Arrived" until the restaurant informs Hungry Hub Team otherwise. Please contact Hungry Hub @ https://line.me/R/ti/p/%40zmr6478h<br>
    or call 081 939 1600 if you have any questions.
  BODY
  subject = "ลูกค้ามีการส่งคำร้องโต้แย้งปฏิเสธสถานะ 'No Show' /Customer No Show Dispute "
  UserMailer.notify_support(subject, message).deliver_later!
  OwnerMailer.notify_managers(restaurant.id, subject, message).deliver_later!
end

#fix_incorrect_validation(invalid_case) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/my_lib/agents/update_booking_status_for_user.rb', line 41

def fix_incorrect_validation(invalid_case)
  case invalid_case
  when :no_show
    customer_dispute_no_show
  when :cancel
    customer_did_not_show_up
  else
    APMErrorHandler.report('not detected', invalid_case: invalid_case)
    false
  end

  true
rescue StandardError => e
  HH_LOGGER.info e
  false
end

#update_booking!Object



10
11
12
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
# File 'app/my_lib/agents/update_booking_status_for_user.rb', line 10

def update_booking!
  if reservation.is_past?
    normal_error!
    errors.add(:base, 'Reservation has passed')
    raise(InvalidReservation, 'User trying to edit past reservation')
  end

  if only_sr_changed?
    @agent = UpdateSpecialRequest.new(reservation, reservation_params.merge(modified_by: :user))
    @agent.execute!
  elsif primary_attr_changed?
    @agent = ModifyBookingForUser.new(reservation, reservation_params)
    @agent.execute!
    @reservation = @agent.reservation
  elsif cancelled?
    @agent = CancelReservationService.new(reservation.id, :user)
    @agent.execute
  elsif reservation.changes.present?
    APMErrorHandler.report 'not detected', reservation: reservation,
                                           changes: reservation.changes
  end

  true
rescue InvalidReservation, ActiveRecord::ActiveRecordError, ModifyBookingForUser::NotModified => e
  if @agent
    self.errors = @agent.errors
    overwrite_error_type!(@agent.error_type) if @agent.respond_to?(:error_type)
  end
  raise(e)
end