-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add after_save: send_email logic on EventAttendee
- Loading branch information
1 parent
6bbf211
commit 392d7ff
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 |