search attachments inside bloc repetables

This commit is contained in:
clemkeirua 2019-09-03 15:17:19 +02:00 committed by Pierre de La Morinerie
parent cce84a4209
commit feb9c32537
3 changed files with 38 additions and 3 deletions

View file

@ -1,8 +1,12 @@
class PiecesJustificativesService
def self.liste_pieces_justificatives(dossier)
dossier.champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
.filter { |pj| pj.piece_justificative_file.attached? }
champs_blocs_repetables = dossier.champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
.flat_map(&:champs)
champs_pieces_justificatives_with_attachments(
champs_blocs_repetables + dossier.champs
)
end
def self.pieces_justificatives_total_size(dossier)
@ -37,4 +41,12 @@ class PiecesJustificativesService
}
end
end
private
def self.champs_pieces_justificatives_with_attachments(champs)
champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
.filter { |pj| pj.piece_justificative_file.attached? }
end
end