[#2750] Move filtered_ids to ProcedurePresentation
This commit is contained in:
parent
0e9b40ccf6
commit
2e9dafb4c3
5 changed files with 110 additions and 105 deletions
|
@ -52,6 +52,44 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def filtered_ids(dossiers, statut)
|
||||
filters[statut].map do |filter|
|
||||
table = filter['table']
|
||||
column = dossier_field_service.sanitized_column(filter)
|
||||
case table
|
||||
when 'self'
|
||||
dossiers.where("? ILIKE ?", filter['column'], "%#{filter['value']}%")
|
||||
|
||||
when 'france_connect_information'
|
||||
dossiers
|
||||
.includes(user: :france_connect_information)
|
||||
.where("? ILIKE ?", "france_connect_informations.#{filter['column']}", "%#{filter['value']}%")
|
||||
|
||||
when 'type_de_champ', 'type_de_champ_private'
|
||||
relation = table == 'type_de_champ' ? :champs : :champs_private
|
||||
dossiers
|
||||
.includes(relation)
|
||||
.where("champs.type_de_champ_id = ?", filter['column'].to_i)
|
||||
.where("champs.value ILIKE ?", "%#{filter['value']}%")
|
||||
when 'etablissement'
|
||||
if filter['column'] == 'entreprise_date_creation'
|
||||
date = filter['value'].to_date rescue nil
|
||||
dossiers
|
||||
.includes(table)
|
||||
.where("#{column} = ?", date)
|
||||
else
|
||||
dossiers
|
||||
.includes(table)
|
||||
.where("#{column} ILIKE ?", "%#{filter['value']}%")
|
||||
end
|
||||
when 'user'
|
||||
dossiers
|
||||
.includes(table)
|
||||
.where("#{column} ILIKE ?", "%#{filter['value']}%")
|
||||
end.pluck(:id)
|
||||
end.reduce(:&)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier_field_service
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue