2023-04-22 19:54:41 +02:00
|
|
|
module DossierSearchableConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2024-04-03 10:21:50 +02:00
|
|
|
after_commit :update_search_terms_later
|
2023-04-22 19:54:41 +02:00
|
|
|
|
|
|
|
def update_search_terms
|
2024-04-03 10:21:50 +02:00
|
|
|
search_terms = [
|
2023-04-22 19:54:41 +02:00
|
|
|
user&.email,
|
|
|
|
*champs_public.flat_map(&:search_terms),
|
|
|
|
*etablissement&.search_terms,
|
|
|
|
individual&.nom,
|
|
|
|
individual&.prenom
|
|
|
|
].compact_blank.join(' ')
|
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
private_search_terms = champs_private.flat_map(&:search_terms).compact_blank.join(' ')
|
|
|
|
|
|
|
|
sql = "UPDATE dossiers SET search_terms = :search_terms, private_search_terms = :private_search_terms WHERE id = :id"
|
|
|
|
sanitized_sql = self.class.sanitize_sql_array([sql, search_terms:, private_search_terms:, id:])
|
|
|
|
self.class.connection.execute(sanitized_sql)
|
2023-04-22 19:54:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_search_terms_later
|
|
|
|
DossierUpdateSearchTermsJob.perform_later(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|