Use enum to the fullest with TypeDeChamp.type_champs

This commit is contained in:
gregoirenovel 2018-08-28 16:22:34 +02:00
parent 16a719922b
commit 2d3b553e4d
21 changed files with 94 additions and 94 deletions

View file

@ -13,17 +13,17 @@ class ChampsService
def check_piece_justificative_files(champs)
champs.select do |champ|
champ.type_champ == 'piece_justificative'
champ.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
end.map { |c| c.piece_justificative_file_errors }.flatten
end
private
def fill_champs(champs, h)
datetimes, not_datetimes = champs.partition { |c| c.type_champ == 'datetime' }
datetimes, not_datetimes = champs.partition { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
not_datetimes.each do |c|
if c.type_champ == 'piece_justificative' && h["champs"]["'#{c.id}'"].present?
if c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) && h["champs"]["'#{c.id}'"].present?
c.piece_justificative_file.attach(h["champs"]["'#{c.id}'"])
else
c.value = h[:champs]["'#{c.id}'"]