Module: NotificationWorkers::ReservationModules::BookingCancellation

Included in:
NotificationWorkers::Reservation
Defined in:
app/workers/notification_workers/reservation_modules/booking_cancellation.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#alert_booking_cancellation_by_email(rules) ⇒ Object



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
# File 'app/workers/notification_workers/reservation_modules/booking_cancellation.rb', line 44

def alert_booking_cancellation_by_email(rules)
  # Send to admin
  if rules[:receiver].include?('admin')
    safe_call do
      subject = "Owner cancelled customer\\'s booking"
      restaurant = reservation.restaurant
      message = <<~BODY
        #{restaurant.name} has cancelled customer Id # #{reservation.id} @ #{Time.current_time.to_s(:db)}
        Reason: #{reservation.cancel_reason}
        Customer Name : #{reservation.name}
        Customer Email: #{reservation.email}
        Booking Day: #{reservation.date}
        Booking Start Time: #{reservation.start_time_format}
        Booking Party Size: #{reservation.party_size}
      BODY

      # Get account manager email if available
       = restaurant.user&.email
      options = {
        notes: { reservation_id: reservation.id, error_name: 'Owner cancelled booking' },
        receivers: [],
      }

      # Add account manager email to receivers if present
      options[:receivers] <<  if .present?

      report["#{__callee__}_to_staff"] = StaffMailer.notify_error_staff(subject, message, options).deliver_later!
    end
  end
end

#notif_booking_cancellation_by_email(rules) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/workers/notification_workers/reservation_modules/booking_cancellation.rb', line 21

def notif_booking_cancellation_by_email(rules)
  # Send to owner
  if rules[:receiver].include?('owner')
    report["#{__callee__}_to_owner"] = safe_call do
      OwnerMailer.booking_cancel(reservation.id).deliver_later!
    end
  end

  # Send to admin
  if rules[:receiver].include?('admin')
    report["#{__callee__}_to_admin"] = safe_call do
      StaffMailer.booking_cancel(reservation.id).deliver_later!
    end
  end

  # Send to user
  if allow_send_notif_to_user?(receivers: rules[:receiver])
    report["#{__callee__}_to_user"] = safe_call do
      UserMailer.booking_cancel(reservation.id, reservation.user_id).deliver_later!
    end
  end
end

#notif_booking_cancellation_by_sms(rules) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/workers/notification_workers/reservation_modules/booking_cancellation.rb', line 5

def notif_booking_cancellation_by_sms(rules)
  # Send to owner
  if rules[:receiver].include?('owner')
    report["#{__callee__}_to_owner"] = safe_call do
      sms_owner_notifier.send_cancel_msg
    end
  end

  # Send to admin
  if rules[:receiver].include?('admin')
    report["#{__callee__}_to_admin"] = safe_call do
      sms_admin_notifier.send_cancel_msg
    end
  end
end