Module: NotificationWorkers::ReservationModules::SharedMethods

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

Instance Method Summary collapse

Instance Method Details

#ack?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


61
62
63
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 61

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

Parameters:

  • receivers (Hash)

    The receivers of the notification.

Returns:

  • (Boolean)

    Returns true if notifications can be sent; false otherwise.



151
152
153
154
155
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 151

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

Returns:

  • (Boolean)


56
57
58
59
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 56

def before_dining_time?
  now = Time.now_in_tz(restaurant.time_zone)
  now < reservation.reservation_time
end

#create_gcal_event(rules) ⇒ Object



101
102
103
104
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
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 101

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

#gcalObject



44
45
46
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 44

def gcal
  @gcal ||= GoogleCalendar::Base.new
end

#gcal_normalized_dataObject

normalize reservation data to be compatible with google calendar event format



94
95
96
97
98
99
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 94

def gcal_normalized_data
  @gcal_normalized_data ||= begin
    normalizer = GoogleCalendar::Normalizer.new(reservation)
    normalizer.normalized_data
  end
end

#has_no_packages?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 69

def has_no_packages?
  !has_packages?
end

#has_packages?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 65

def has_packages?
  reservation&.property&.package&.present?
end

#manual_booking?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 48

def manual_booking?
  reservation.private_channel?
end

#no_ack?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 32

def no_ack?
  !ack?
end

#no_offers?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 40

def no_offers?
  !offers?
end

#not_last_minute?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


52
53
54
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 52

def not_manual_booking?
  !manual_booking?
end

#not_temporary?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


36
37
38
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 36

def offers?
  restaurant.any_offers?
end

#reached_goal?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 20

def reached_goal?
  reservation.reached_goal?
end

#sms_admin_no_ack_notifierObject



88
89
90
91
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 88

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_notifierObject



83
84
85
86
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 83

def sms_admin_notifier
  @sms_admin_notifier ||= NotificationService::Sms.new(phones: AdminSetting.support_phone, reservation: reservation,
                                                       default_locale: :en)
end

#sms_owner_notifierObject



73
74
75
76
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 73

def sms_owner_notifier
  @sms_owner_notifier ||= NotificationService::Sms.new(phones: owner.phone, reservation: reservation,
                                                       default_locale: :en)
end

#sms_user_notifierObject



78
79
80
81
# File 'app/workers/notification_workers/reservation_modules/shared_methods.rb', line 78

def sms_user_notifier
  @sms_user_notifier ||= NotificationService::Sms.new(phones: reservation.phone, reservation: reservation,
                                                      default_locale: :en)
end

#waiting_for_payment?Boolean

Returns:

  • (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