Skip to content

Commit

Permalink
Add after_save: send_email logic on EventAttendee
Browse files Browse the repository at this point in the history
  • Loading branch information
janwerkhoven committed Apr 18, 2024
1 parent 6bbf211 commit 392d7ff
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions app/models/event_attendee.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'postmark/api'
require 'ap'

# == Schema Information
#
# Table name: event_attendees
Expand All @@ -17,4 +20,68 @@
class EventAttendee < ApplicationRecord
belongs_to :event
belongs_to :person, optional: true

after_save :send_confirmation_emails

private

def send_confirmation_emails
log.info "✅ EventAttendee #{id} saved"

return if email.nil?

# TODO: Prevent this email from being sent upon every save...

template_locale = locale == 'fr' ? 'fr' : 'en'

log.info '✅ creating confirmation email'

EmailAttempt.create!(
to: email,
from: 'Interflux Electronics <[email protected]>',
reply_to: 'Interflux Electronics <[email protected]>',
# provider: :postmark,
postmark_stream: 'outbound',
postmark_template_alias: "interflux-event-registration-1-#{template_locale}",
postmark_template_model: {
first_name: first_name,
last_name: last_name,
event_name: event.name,
event_dates: event.start_to_end_date,
event_location: event.location
},
created_by: self
)

log.info '✅ creating internal email'

EmailAttempt.create!(
to: 'Steven Teliszewski <[email protected]>',
cc: 'Jan Werkhoven <[email protected]>',
from: 'Interflux Electronics <[email protected]>',
reply_to: 'Interflux Electronics <[email protected]>',
# provider: :postmark,
postmark_stream: 'outbound',
postmark_template_alias: 'interflux-event-registration-2-en',
postmark_template_model: {
receiver: {
first_name: 'Steven'
},
attendee: {
first_name: first_name,
last_name: last_name,
role: role,
company: company,
email: email,
locale: locale
},
event: {
name: event.name,
dates: event.start_to_end_date,
location: event.location
}
},
created_by: self
)
end
end

0 comments on commit 392d7ff

Please sign in to comment.