fetch pjs_for_commentaires by dossiers
This commit is contained in:
parent
5631141a46
commit
11aedb2dc8
1 changed files with 14 additions and 9 deletions
|
@ -1,12 +1,11 @@
|
||||||
class PiecesJustificativesService
|
class PiecesJustificativesService
|
||||||
def self.liste_documents(dossiers, for_expert)
|
def self.liste_documents(dossiers, for_expert)
|
||||||
pj_and_paths = pjs_for_champs(dossiers, for_expert)
|
pj_and_paths = pjs_for_champs(dossiers, for_expert) +
|
||||||
|
pjs_for_commentaires(dossiers)
|
||||||
|
|
||||||
pj_and_paths += dossiers.flat_map do |dossier|
|
pj_and_paths += dossiers.flat_map do |dossier|
|
||||||
pjs = pjs_for_commentaires(dossier) +
|
|
||||||
pjs_for_dossier(dossier, for_expert)
|
pjs_for_dossier(dossier, for_expert)
|
||||||
|
.map { |piece_justificative| ActiveStorage::DownloadableFile.pj_and_path(dossier.id, piece_justificative) }
|
||||||
pjs.map { |piece_justificative| ActiveStorage::DownloadableFile.pj_and_path(dossier.id, piece_justificative) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pj_and_paths
|
pj_and_paths
|
||||||
|
@ -133,14 +132,20 @@ class PiecesJustificativesService
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pjs_for_commentaires(dossier)
|
def self.pjs_for_commentaires(dossiers)
|
||||||
commentaires = Commentaire
|
commentaire_id_dossier_id = Commentaire
|
||||||
.joins(:piece_jointe_attachment)
|
.joins(:piece_jointe_attachment)
|
||||||
.where(dossier: dossier)
|
.where(dossier: dossiers)
|
||||||
|
.pluck(:id, :dossier_id)
|
||||||
|
.to_h
|
||||||
|
|
||||||
ActiveStorage::Attachment
|
ActiveStorage::Attachment
|
||||||
.includes(:blob)
|
.includes(:blob)
|
||||||
.where(record_type: "Commentaire", record_id: commentaires.ids)
|
.where(record_type: "Commentaire", record_id: commentaire_id_dossier_id.keys)
|
||||||
|
.map do |a|
|
||||||
|
dossier_id = commentaire_id_dossier_id[a.record_id]
|
||||||
|
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pjs_for_dossier(dossier, for_expert = false)
|
def self.pjs_for_dossier(dossier, for_expert = false)
|
||||||
|
|
Loading…
Reference in a new issue