mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 03:59:33 +02:00
refactored
This commit is contained in:
parent
64a7e0fb53
commit
59fb12b840
2 changed files with 13 additions and 2 deletions
|
@ -3,9 +3,11 @@ class VerifyEmailsJob < ApplicationJob
|
||||||
|
|
||||||
def perform(contact_id:, check_level: 'regex')
|
def perform(contact_id:, check_level: 'regex')
|
||||||
contact = Contact.find_by(id: contact_id)
|
contact = Contact.find_by(id: contact_id)
|
||||||
|
|
||||||
|
return if check_contact_for_duplicate_mail(contact_id)
|
||||||
|
|
||||||
contact_not_found(contact_id) unless contact
|
contact_not_found(contact_id) unless contact
|
||||||
validate_check_level(check_level)
|
validate_check_level(check_level)
|
||||||
|
|
||||||
action = Actions::EmailCheck.new(email: contact.email,
|
action = Actions::EmailCheck.new(email: contact.email,
|
||||||
validation_eventable: contact,
|
validation_eventable: contact,
|
||||||
check_level: check_level)
|
check_level: check_level)
|
||||||
|
@ -17,6 +19,16 @@ class VerifyEmailsJob < ApplicationJob
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_contact_for_duplicate_mail(contact_id)
|
||||||
|
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||||
|
contact = Contact.find(contact_id)
|
||||||
|
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
||||||
|
|
||||||
|
r = ValidationEvent.where(validation_eventable_id: contact_ids)
|
||||||
|
|
||||||
|
r.present?
|
||||||
|
end
|
||||||
|
|
||||||
def contact_not_found(contact_id)
|
def contact_not_found(contact_id)
|
||||||
raise StandardError, "Contact with contact_id #{contact_id} not found"
|
raise StandardError, "Contact with contact_id #{contact_id} not found"
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,6 @@ def prepare_contacts(options)
|
||||||
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
|
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
|
||||||
|
|
||||||
Contact.where.not(id: validation_events_ids)
|
Contact.where.not(id: validation_events_ids)
|
||||||
# contacts.reject(&:need_to_start_force_delete?) # temporarily commented out code
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue