Class: NotificationService::Email
- Inherits:
-
Object
- Object
- NotificationService::Email
- Defined in:
- app/services/notification_service/email.rb
Overview
typed: ignore frozen_string_literal: true
Instance Attribute Summary collapse
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
-
#reservation ⇒ Object
Returns the value of attribute reservation.
-
#restaurant ⇒ Object
Returns the value of attribute restaurant.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(receiver:, user: nil, reservation: nil, restaurant: nil, owner: nil) ⇒ Email
constructor
A new instance of Email.
- #points_expiration_reminder ⇒ Object
- #send_cancel_email ⇒ Object
- #send_confirmation_email ⇒ Object
- #send_modification_email ⇒ Object
- #send_pending_email ⇒ Object
Constructor Details
#initialize(receiver:, user: nil, reservation: nil, restaurant: nil, owner: nil) ⇒ Email
Returns a new instance of Email.
12 13 14 15 16 17 18 |
# File 'app/services/notification_service/email.rb', line 12 def initialize(receiver:, user: nil, reservation: nil, restaurant: nil, owner: nil) @receiver = receiver @user = user @reservation = reservation @restaurant = restaurant @owner = owner end |
Instance Attribute Details
#owner ⇒ Object
Returns the value of attribute owner.
5 6 7 |
# File 'app/services/notification_service/email.rb', line 5 def owner @owner end |
#receiver ⇒ Object
Returns the value of attribute receiver.
5 6 7 |
# File 'app/services/notification_service/email.rb', line 5 def receiver @receiver end |
#reservation ⇒ Object
Returns the value of attribute reservation.
5 6 7 |
# File 'app/services/notification_service/email.rb', line 5 def reservation @reservation end |
#restaurant ⇒ Object
Returns the value of attribute restaurant.
5 6 7 |
# File 'app/services/notification_service/email.rb', line 5 def restaurant @restaurant end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'app/services/notification_service/email.rb', line 5 def user @user end |
Instance Method Details
#points_expiration_reminder ⇒ Object
117 118 119 |
# File 'app/services/notification_service/email.rb', line 117 def points_expiration_reminder UserMailer.notify_points_expiration(user).deliver_later! end |
#send_cancel_email ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/notification_service/email.rb', line 44 def send_cancel_email return if reservation.dummy? user_id = user.present? ? user.id : nil case receiver when :owner OwnerMailer.booking_cancel(reservation.id).deliver_later! when :user UserMailer.booking_cancel(reservation.id, user_id).deliver_later! when :staff StaffMailer.booking_cancel(reservation.id).deliver_later! else APMErrorHandler.report('receiver is undefined', receiver: receiver.to_s) end end |
#send_confirmation_email ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/notification_service/email.rb', line 28 def send_confirmation_email user_id = user.present? ? user.id : nil case receiver when :owner # there is a case where id is nil, so we use `deliver!` instead of `deliver_later!` # to track the error OwnerMailer.booking_confirmation(reservation.id).deliver! when :user UserMailer.booking_confirmation(reservation.id, user_id).deliver_later! when :staff StaffMailer.booking_confirm(reservation.id).deliver_later! else APMErrorHandler.report('receiver is undefined', receiver: receiver.to_s) end end |
#send_modification_email ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/services/notification_service/email.rb', line 71 def send_modification_email # Add comprehensive tracking for booking modification email ElasticAPM.with_span('NotificationService::Email#send_modification_email', 'service') do # Validate reservation exists if reservation.nil? error_context = { receiver: receiver, user_id: user&.id, caller_stack: capture_stack_trace, } APMErrorHandler.report( 'NotificationService::Email#send_modification_email called with nil reservation', context: error_context, handled: true, ) return false end # Validate reservation has an ID if reservation.id.nil? error_context = { receiver: receiver, reservation_present: reservation.present?, reservation_class: reservation.class.name, reservation_attributes: reservation.attributes.slice('id', 'created_at', 'updated_at'), user_id: user&.id, caller_stack: capture_stack_trace, } APMErrorHandler.report( 'NotificationService::Email#send_modification_email called with reservation without ID', context: error_context, handled: true, ) return false end user_id = user.present? ? user.id : nil if receiver == :user UserMailer.booking_modification(reservation.id, user_id).deliver_later! end end end |
#send_pending_email ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'app/services/notification_service/email.rb', line 60 def send_pending_email case receiver when :user UserMailer.booking_pending(reservation.id).deliver_later! when :staff StaffMailer.booking_pending(reservation.id).deliver_later! else APMErrorHandler.report('receiver is undefined', receiver: receiver.to_s) end end |