Skip to content

Commit

Permalink
refactor: always use column.value
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Nov 13, 2024
1 parent 888a95b commit f2e3402
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions app/services/dossier_projection_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def self.project(dossiers_ids, columns)
{ TABLE => c.table, COLUMN => c.column }
end
end
champ_value = champ_value_formatter(dossiers_ids, fields)

individual_first_name = { TABLE => 'individual', COLUMN => 'prenom' }
individual_last_name = { TABLE => 'individual', COLUMN => 'nom' }
Expand All @@ -72,9 +71,8 @@ def self.project(dossiers_ids, columns)
fields
.filter { |f| f[STABLE_ID] == stable_id }
.each do |field|
column = field[:original_column]
field[:id_value_h] = champs.to_h { [_1.dossier_id, column.is_a?(Columns::JSONPathColumn) ? column.value(_1) : champ_value.(_1)] }
end
field[:id_value_h] = champs.to_h { |c| [c.dossier_id, field[:original_column].value(c)] }

Check warning on line 74 in app/services/dossier_projection_service.rb

View check run for this annotation

Codecov / codecov/patch

app/services/dossier_projection_service.rb#L74

Added line #L74 was not covered by tests
end
end
when 'self'
Dossier
Expand Down Expand Up @@ -178,28 +176,4 @@ def self.project(dossiers_ids, columns)
)
end
end

class << self
private

def champ_value_formatter(dossiers_ids, fields)
stable_ids = fields.filter { _1[TABLE].in?(['type_de_champ']) }.map { _1[STABLE_ID] }

revision_ids_by_dossier_ids = Dossier.where(id: dossiers_ids).pluck(:id, :revision_id).to_h

stable_ids_and_types_de_champ_by_revision_ids = ProcedureRevisionTypeDeChamp.includes(:type_de_champ)
.where(revision_id: revision_ids_by_dossier_ids.values.uniq, type_de_champ: { stable_id: stable_ids })
.map { [_1.revision_id, _1.type_de_champ] }
.group_by(&:first)
.transform_values { _1.map { |_, type_de_champ| [type_de_champ.stable_id, type_de_champ] }.to_h }

stable_ids_and_types_de_champ_by_dossier_ids = revision_ids_by_dossier_ids.transform_values { stable_ids_and_types_de_champ_by_revision_ids[_1] }.compact

-> (champ) {
type_de_champ = stable_ids_and_types_de_champ_by_dossier_ids
.fetch(champ.dossier_id, {})[champ.stable_id]
type_de_champ&.champ_value(champ)
}
end
end
end

0 comments on commit f2e3402

Please sign in to comment.