demarches-normaliennes/app/services/update_zone_to_procedures_service.rb

22 lines
530 B
Ruby
Raw Normal View History

2021-12-15 19:36:02 +01:00
class UpdateZoneToProceduresService
def self.call(lines)
errors = []
lines.each do |line|
zone_label = line["POL_PUB_MINISTERE RATTACHEMENT"]
zone = Zone.find_by(acronym: zone_label)
if zone.nil?
errors << "Zone #{zone_label} introuvable"
else
id = line["id"]
procedure = Procedure.find_by(id: id)
if procedure
procedure.update(zone: zone)
else
errors << "Procedure #{id} introuvable"
end
end
end
errors
end
end