Module: NotificationWorkers::ReservationModules::SharedMethods
- Included in:
- NotificationWorkers::Reservation
- Defined in:
- app/workers/notification_workers/reservation_modules/shared_methods.rb
Instance Method Summary collapse
- #ack? ⇒ Boolean
- #after_dining_time? ⇒ Boolean
-
#allow_send_notif_to_user?(receivers:) ⇒ Boolean
No need send the notification to user if the booking channel is come from vendors Because vendors is handle the notification by themself So if we also send notification to user, it will be duplicated and make user confused.
- #before_dining_time? ⇒ Boolean
- #create_gcal_event(rules) ⇒ Object
- #gcal ⇒ Object
-
#gcal_normalized_data ⇒ Object
normalize reservation data to be compatible with google calendar event format.
- #has_no_packages? ⇒ Boolean
- #has_packages? ⇒ Boolean
- #manual_booking? ⇒ Boolean
- #no_ack? ⇒ Boolean
- #no_offers? ⇒ Boolean
- #not_last_minute? ⇒ Boolean
- #not_manual_booking? ⇒ Boolean
- #not_temporary? ⇒ Boolean
- #not_waiting_for_payment? ⇒ Boolean
- #offers? ⇒ Boolean
- #reached_goal? ⇒ Boolean
- #rejected? ⇒ Boolean
- #sms_admin_no_ack_notifier ⇒ Object
- #sms_admin_notifier ⇒ Object
- #sms_owner_notifier ⇒ Object
- #sms_user_notifier ⇒ Object
- #waiting_for_payment? ⇒ Boolean
Instance Method Details
#ack? ⇒ Boolean
28 29 30 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 28 def ack? reservation.ack == true end |
#after_dining_time? ⇒ Boolean
65 66 67 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 65 def after_dining_time? !before_dining_time? end |
#allow_send_notif_to_user?(receivers:) ⇒ Boolean
No need send the notification to user if the booking channel is come from vendors Because vendors is handle the notification by themself So if we also send notification to user, it will be duplicated and make user confused
155 156 157 158 159 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 155 def allow_send_notif_to_user?(receivers:) return false if receivers.blank? receivers.include?('user') && !reservation.booking_channel.skip_send_notifications?(actor: 'user') end |
#before_dining_time? ⇒ Boolean
60 61 62 63 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 60 def before_dining_time? now = Time.now_in_tz(restaurant.time_zone) now < reservation.reservation_time end |
#create_gcal_event(rules) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 105 def create_gcal_event(rules) if rules[:receiver].include?('user') return if reservation.dummy? unless Figaro.bool_env!('SIDEKIQ_CREATE_GOOGLE_CALENDAR_EVENT') report[:create_gcal_event_by_user] = 'gcal-id-12323' return end report[__callee__.to_s] = safe_call do email = reservation.email.to_s.strip if EmailValidator.valid?(email) event_data = GCalendar::Event.new(gcal_normalized_data) event_attr = { visibility: 'public', summary: "Reservation for #{restaurant.name}", attendees: [ { email: email, additional_guests: reservation.party_size - 1, comment: reservation.special_request, display_name: reservation.username, response_status: 'accepted', }, ], description: "-- Reservations Details --\n" \ "Diner's Name: #{reservation.username}\n" \ "Diner's Phone: #{reservation.phone}\n" \ "Date: #{reservation.date_format}\n" \ "Time: #{reservation.start_time_format} (Restaurant's local time)\n" \ "Party Size: #{reservation.party_size}\n" \ "Special Request: #{reservation.special_request.presence || '-'}\n" \ "Reservation No: #{reservation.id}", } event_data.update!(event_attr) event = GCalendar::Event.new(event_data.to_h) calendar = gcal.client.insert_event(GoogleCalendar::Base::CALENDAR_ID, event) reservation.update_column(:gcal_id, calendar.id) calendar.id end end end end |
#gcal ⇒ Object
48 49 50 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 48 def gcal @gcal ||= GoogleCalendar::Base.new end |
#gcal_normalized_data ⇒ Object
normalize reservation data to be compatible with google calendar event format
98 99 100 101 102 103 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 98 def gcal_normalized_data @gcal_normalized_data ||= begin normalizer = GoogleCalendar::Normalizer.new(reservation) normalizer.normalized_data end end |
#has_no_packages? ⇒ Boolean
73 74 75 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 73 def has_no_packages? !has_packages? end |
#has_packages? ⇒ Boolean
69 70 71 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 69 def has_packages? reservation&.property&.package&.present? end |
#manual_booking? ⇒ Boolean
52 53 54 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 52 def manual_booking? reservation.private_channel? end |
#no_ack? ⇒ Boolean
32 33 34 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 32 def no_ack? !ack? end |
#no_offers? ⇒ Boolean
44 45 46 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 44 def no_offers? !offers? end |
#not_last_minute? ⇒ Boolean
24 25 26 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 24 def not_last_minute? !last_minute? end |
#not_manual_booking? ⇒ Boolean
56 57 58 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 56 def not_manual_booking? !manual_booking? end |
#not_temporary? ⇒ Boolean
8 9 10 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 8 def not_temporary? !reservation.is_temporary? end |
#not_waiting_for_payment? ⇒ Boolean
16 17 18 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 16 def not_waiting_for_payment? !waiting_for_payment? end |
#offers? ⇒ Boolean
40 41 42 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 40 def offers? restaurant.any_offers? end |
#reached_goal? ⇒ Boolean
20 21 22 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 20 def reached_goal? reservation.reached_goal? end |
#rejected? ⇒ Boolean
36 37 38 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 36 def rejected? reservation.rejected? end |
#sms_admin_no_ack_notifier ⇒ Object
92 93 94 95 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 92 def sms_admin_no_ack_notifier @sms_admin_no_ack_notifier ||= NotificationService::Sms.new(phones: AdminSetting.reservation_no_ack_hotline, reservation: reservation, default_locale: :en) end |
#sms_admin_notifier ⇒ Object
87 88 89 90 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 87 def sms_admin_notifier @sms_admin_notifier ||= NotificationService::Sms.new(phones: AdminSetting.support_phone, reservation: reservation, default_locale: :en) end |
#sms_owner_notifier ⇒ Object
77 78 79 80 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 77 def sms_owner_notifier @sms_owner_notifier ||= NotificationService::Sms.new(phones: owner.phone, reservation: reservation, default_locale: :en) end |
#sms_user_notifier ⇒ Object
82 83 84 85 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 82 def sms_user_notifier @sms_user_notifier ||= NotificationService::Sms.new(phones: reservation.phone, reservation: reservation, default_locale: :en) end |
#waiting_for_payment? ⇒ Boolean
12 13 14 |
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 12 def waiting_for_payment? reservation.is_temporary == false && reservation.status_as_symbol == :waiting_for_payment end |