2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-06 17:12:00 +02:00
|
|
|
module UserFindByConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def self.by_email(email)
|
|
|
|
find_by(users: { email: email })
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_all_by_identifier(ids: [], emails: [])
|
|
|
|
find_all_by_identifier_with_emails(ids:, emails:).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_all_by_identifier_with_emails(ids: [], emails: [])
|
2024-02-13 10:37:03 +01:00
|
|
|
valid_emails, invalid_emails = emails.partition { StrictEmailValidator::REGEXP.match?(_1) }
|
2023-10-06 17:12:00 +02:00
|
|
|
|
|
|
|
[
|
|
|
|
where(id: ids).or(where(users: { email: valid_emails })).distinct(:id),
|
|
|
|
valid_emails,
|
|
|
|
invalid_emails
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|