clean(tech): EmailChecker, use class method, not instance

This commit is contained in:
mfo 2024-07-01 10:38:43 +02:00
parent 554141bb67
commit ced634295e
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
6 changed files with 25 additions and 31 deletions

View file

@ -9,17 +9,11 @@ module Administrateurs
end
def create
email_checker = EmailChecker.new
emails = params['emails'].presence || [].to_json
emails = JSON.parse(emails).map { EmailSanitizer.sanitize(_1) }
@maybe_typo, emails = emails.map do |email|
result = email_checker.check(email: email)
if result[:email_suggestions].present?
[email, result[:email_suggestions].first]
else
[email, nil]
end
end.partition { _1[1].present? }
@maybe_typo, emails = emails
.map { |email| [email, EmailChecker.check(email:)[:suggestions]&.first] }
.partition { _1[1].present? }
errors = if !@maybe_typo.empty?
["Attention, nous pensons avoir identifié une faute de frappe dans les invitations : #{@maybe_typo.map(&:first).join(', ')}"]
else

View file

@ -1,5 +1,5 @@
class EmailCheckerController < ApplicationController
def show
render json: EmailChecker.new.check(email: params[:email])
render json: EmailChecker.check(email: params[:email])
end
end