2023-09-05 11:15:12 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-11 14:21:51 +02:00
|
|
|
# Send a notification to users who did not upload their supporting document files yet
|
2023-09-05 11:15:12 +02:00
|
|
|
class SupportingDocumentsReminderWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform
|
|
|
|
users_to_notify = User.members
|
|
|
|
.supporting_documents_reminder_not_sent
|
|
|
|
.where("users.created_at < ?", 2.days.ago)
|
|
|
|
.left_outer_joins(supporting_document_files: { supporting_document_type: :groups })
|
|
|
|
.where("groups.id = users.group_id OR groups.id IS NULL")
|
|
|
|
.select("users.*, count(supporting_document_files.id)")
|
|
|
|
.group("users.id")
|
|
|
|
.having("(count(supporting_document_files.id)) < (SELECT count(supporting_document_types.id) "\
|
|
|
|
"FROM supporting_document_types "\
|
|
|
|
"INNER JOIN supporting_document_types_groups "\
|
|
|
|
"ON supporting_document_types_groups.supporting_document_type_id = supporting_document_types.id "\
|
|
|
|
"WHERE supporting_document_types_groups.group_id = users.group_id)")
|
|
|
|
users_to_notify.each do |user|
|
|
|
|
NotificationCenter.call type: 'notify_user_supporting_document_reminder',
|
|
|
|
receiver: user,
|
|
|
|
attached_object: user
|
|
|
|
user.update_column(:supporting_documents_reminder_sent_at, DateTime.current)
|
|
|
|
end
|
|
|
|
end
|
2023-09-11 14:45:31 +02:00
|
|
|
end
|