refactor(pj_service): do not query for pj_index

This commit is contained in:
simon lehericey 2024-05-01 21:23:41 +02:00
parent 6d757db20b
commit b656867836
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 11 additions and 8 deletions

View file

@ -158,13 +158,16 @@ class PiecesJustificativesService
.includes(:blob)
.where(record_type: "Champ", record_id: champ_id_dossier_id.keys)
.filter { |a| safe_attachment(a) }
.map do |a, _i|
dossier_id = champ_id_dossier_id[a.record_id]
pj_index = Champ.find(a.record_id).piece_justificative_file.blobs.map(&:id).index(a.blob_id)
.group_by(&:record_id)
.flat_map do |champ_id, attachments|
dossier_id = champ_id_dossier_id[champ_id]
attachments.map.with_index do |attachment, index|
if @export_template
@export_template.attachment_and_path(Dossier.find(dossier_id), a, index: pj_index, row_index: a.record.row_index)
@export_template.attachment_and_path(Dossier.find(dossier_id), attachment, index: index, row_index: attachment.record.row_index)
else
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, attachment)
end
end
end
end

View file

@ -82,7 +82,7 @@ describe PiecesJustificativesService do
subject
end
expect(count).to eq(18)
expect(count).to eq(10)
end
end
end