2022-07-25 17:37:02 +02:00
|
|
|
class APIEntreprise::ServiceJob < APIEntreprise::Job
|
|
|
|
def perform(service_id)
|
|
|
|
service = Service.find(service_id)
|
|
|
|
|
|
|
|
service_params = APIEntreprise::ServiceAdapter.new(service.siret, service_id).to_params
|
|
|
|
service.etablissement_infos = service_params
|
|
|
|
|
2023-10-26 15:49:52 +02:00
|
|
|
code_insee = service.etablissement_infos['code_insee_localite']
|
2024-03-13 10:40:39 +01:00
|
|
|
if code_insee.present?
|
2023-10-26 15:49:52 +02:00
|
|
|
service.departement = CodeInsee.new(code_insee).to_departement
|
|
|
|
end
|
|
|
|
|
2024-03-13 10:40:39 +01:00
|
|
|
if service_params[:adresse].present?
|
|
|
|
point = Geocoder.search(service_params[:adresse], params: { citycode: code_insee, limit: 1 }).first
|
|
|
|
|
|
|
|
service.etablissement_lat = point&.latitude
|
|
|
|
service.etablissement_lng = point&.longitude
|
|
|
|
else
|
|
|
|
service.etablissement_lat = nil
|
|
|
|
service.etablissement_lng = nil
|
|
|
|
end
|
|
|
|
|
2022-07-25 17:37:02 +02:00
|
|
|
service.save!
|
|
|
|
end
|
|
|
|
end
|