-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy paththree_month_email_service.rb
More file actions
35 lines (30 loc) · 1.4 KB
/
three_month_email_service.rb
File metadata and controls
35 lines (30 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true
class ThreeMonthEmailService
def self.send_chaser
three_month_cutoff = 3.months.ago.beginning_of_day
one_year_cutoff = 1.year.ago.beginning_of_day
recent_attendee_ids = WorkshopInvitation.to_students
.attended
.joins(:workshop)
.where('workshops.date_and_time >= ?', three_month_cutoff)
.select(:member_id)
past_year_attendee_ids = WorkshopInvitation.to_students
.attended
.joins(:workshop)
.where('workshops.date_and_time >= ?', one_year_cutoff)
.select(:member_id)
members = Member.not_banned
.accepted_toc
.joins(:groups)
.merge(Group.students)
.left_joins(:member_email_deliveries)
.where(member_email_deliveries: { id: nil })
.where.not(id: recent_attendee_ids)
.where(id: past_year_attendee_ids)
.distinct
return if members.empty?
members.find_each do |member|
MemberMailer.with(member: member).chaser.deliver_later
end
end
end