refactor(export): do not use dossier.champs in export

This commit is contained in:
Paul Chavard 2024-10-22 12:31:40 +02:00
parent 0e95381002
commit 51a8c3cf98
No known key found for this signature in database
4 changed files with 13 additions and 22 deletions

View file

@ -31,12 +31,6 @@ class Champs::RepetitionChamp < Champ
# The user cannot enter any information here so it doesnt make much sense to search
end
def rows_for_export
row_ids.map.with_index(1) do |row_id, index|
Champs::RepetitionChamp::Row.new(index:, row_id:, dossier:)
end
end
class Row < Hashie::Dash
property :index
property :row_id

View file

@ -107,6 +107,12 @@ module DossierChampsConcern
assign_attributes(champs_attributes:)
end
def repetition_rows_for_export(type_de_champ)
repetition_row_ids(type_de_champ).map.with_index(1) do |row_id, index|
Champs::RepetitionChamp::Row.new(index:, row_id:, dossier: self)
end
end
def repetition_row_ids(type_de_champ)
return [] if !type_de_champ.repetition?

View file

@ -1052,13 +1052,6 @@ class Dossier < ApplicationRecord
}
end
def self.to_feature_collection
{
type: 'FeatureCollection',
features: GeoArea.joins(:champ).where(champ: { dossier: ids }).map(&:to_feature)
}
end
def log_api_entreprise_job_exception(exception)
exceptions = self.api_entreprise_job_exceptions ||= []
exceptions << exception.inspect

View file

@ -47,7 +47,9 @@ class ProcedureExportService
end
def to_geo_json
io = StringIO.new(dossiers.to_feature_collection.to_json)
champs_carte = dossiers.flat_map { _1.filled_champs.filter(&:carte?) }
features = GeoArea.where(champ_id: champs_carte).map(&:to_feature)
io = StringIO.new({ type: 'FeatureCollection', features: }.to_json)
create_blob(io, :json)
end
@ -92,9 +94,9 @@ class ProcedureExportService
end
def etablissements
@etablissements ||= dossiers.flat_map do |dossier|
dossier.champs.filter { _1.is_a?(Champs::SiretChamp) }
end.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
@etablissements ||= dossiers
.flat_map { _1.filled_champs.filter(&:siret?) }
.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
end
def avis
@ -102,16 +104,12 @@ class ProcedureExportService
end
def champs_repetables_options
champs_by_stable_id = dossiers
.flat_map { _1.champs.filter(&:repetition?) }
.group_by(&:stable_id)
procedure
.all_revisions_types_de_champ
.repetition
.filter_map do |type_de_champ_repetition|
types_de_champ = procedure.all_revisions_types_de_champ(parent: type_de_champ_repetition).to_a
rows = champs_by_stable_id.fetch(type_de_champ_repetition.stable_id, []).flat_map(&:rows_for_export)
rows = dossiers.flat_map { _1.repetition_rows_for_export(type_de_champ_repetition) }
if types_de_champ.present? && rows.present?
{