refactor(prefill): use champ_for_update method
This commit is contained in:
parent
0c7bc6b555
commit
25e009df78
2 changed files with 7 additions and 4 deletions
|
@ -23,7 +23,7 @@ class PrefillChamps
|
||||||
.to_h
|
.to_h
|
||||||
|
|
||||||
dossier
|
dossier
|
||||||
.find_champs_by_stable_ids(value_by_stable_id.keys)
|
.champs_for_prefill(value_by_stable_id.keys)
|
||||||
.map { |champ| [champ, value_by_stable_id[champ.stable_id]] }
|
.map { |champ| [champ, value_by_stable_id[champ.stable_id]] }
|
||||||
.map { |champ, value| PrefillValue.new(champ:, value:, dossier:) }
|
.map { |champ, value| PrefillValue.new(champ:, value:, dossier:) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,14 +54,17 @@ class TypesDeChamp::PrefillRepetitionTypeDeChamp < TypesDeChamp::PrefillTypeDeCh
|
||||||
def to_assignable_attributes
|
def to_assignable_attributes
|
||||||
return unless repetition.is_a?(Hash)
|
return unless repetition.is_a?(Hash)
|
||||||
|
|
||||||
row = champ.rows[index] || champ.add_row(champ.dossier_revision)
|
row = champ.rows[index] || champ.add_row(revision)
|
||||||
|
row_id = row.first.row_id
|
||||||
|
|
||||||
repetition.map do |key, value|
|
repetition.map do |key, value|
|
||||||
next unless key.is_a?(String) && key.starts_with?("champ_")
|
next unless key.is_a?(String) && key.starts_with?("champ_")
|
||||||
|
|
||||||
subchamp = row.find { |champ| champ.stable_id == Champ.stable_id_from_typed_id(key) }
|
stable_id = Champ.stable_id_from_typed_id(key)
|
||||||
next unless subchamp
|
type_de_champ = revision.types_de_champ.find { _1.stable_id == stable_id }
|
||||||
|
next unless type_de_champ
|
||||||
|
|
||||||
|
subchamp = champ.dossier.champ_for_update(type_de_champ, row_id)
|
||||||
TypesDeChamp::PrefillTypeDeChamp.build(subchamp.type_de_champ, revision).to_assignable_attributes(subchamp, value)
|
TypesDeChamp::PrefillTypeDeChamp.build(subchamp.type_de_champ, revision).to_assignable_attributes(subchamp, value)
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue