extract pj_path method

This commit is contained in:
simon lehericey 2022-04-04 22:16:33 +02:00
parent 97443e2ff6
commit d5241381eb

View file

@ -3,17 +3,19 @@ class ActiveStorage::DownloadableFile
dossiers.flat_map do |dossier|
dossier_export = PiecesJustificativesService.generate_dossier_export(dossier)
pjs = [dossier_export] + PiecesJustificativesService.liste_documents(dossier, for_expert)
pjs.map do |piece_justificative|
[
piece_justificative,
"dossier-#{dossier.id}/#{self.timestamped_filename(piece_justificative)}"
]
end
pjs.map { |piece_justificative| pj_and_path(dossier, piece_justificative) }
end
end
private
def self.pj_and_path(dossier, pj)
[
pj,
"dossier-#{dossier.id}/#{self.timestamped_filename(pj)}"
]
end
def self.timestamped_filename(attachment)
# we pad the original file name with a timestamp
# and a short id in order to help identify multiple versions and avoid name collisions