added mail contronller and job for notificate registrars and admins about accreditation expire date

This commit is contained in:
olegphenomenon 2021-11-11 12:31:53 +02:00
parent c5719a35f1
commit e74cf2bc7f
7 changed files with 78 additions and 4 deletions

View file

@ -0,0 +1,29 @@
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
MONTH_BEFORE = 5.minute.freeze
def perform
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
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.now.beginning_of_day + MONTH_BEFORE,
Time.now.end_of_day + MONTH_BEFORE).includes(:registrar)
end
def prepare_data_expired_data
ApiUser.where("accreditation_expire_date < ?", Time.now.beginning_of_day).includes(:registrar)
end
end