Merge pull request #2212 from internetee/added_notifications_for_acc_center

added mail contronller and job for notificate registrars and admins about accreditation expire date
This commit is contained in:
Timo Võhmar 2022-01-13 09:23:11 +02:00 committed by GitHub
commit 4ccbbd2292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 167 additions and 4 deletions

View file

@ -0,0 +1,36 @@
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
MONTH_BEFORE = 5.minutes.freeze
def perform
notify_month_before
notify_date_is_expired
end
def notify_month_before
prepare_data_month_before.each do |user|
next if user.registrar.email.nil?
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now
end
end
def notify_date_is_expired
prepare_data_expired_data.each do |user|
next if user.registrar.email.nil?
AccreditationCenterMailer.test_results_are_expired(user.registrar.email).deliver_now
end
end
private
def prepare_data_month_before
ApiUser.where('accreditation_expire_date > ? AND accreditation_expire_date < ?',
Time.zone.now.beginning_of_day + MONTH_BEFORE,
Time.zone.now.end_of_day + MONTH_BEFORE).includes(:registrar)
end
def prepare_data_expired_data
ApiUser.where('accreditation_expire_date < ?', Time.zone.now.beginning_of_day).includes(:registrar)
end
end