Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
prc import ready
Browse files Browse the repository at this point in the history
  • Loading branch information
augnustin committed Jul 27, 2023
1 parent 3681015 commit 29c1488
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ docker-compose.override.yml
/priv/export_fiches_RNCP*.xml
/priv/*.log
/priv/*.csv
!/priv/*.keep.csv

!/**/.gitkeep
/.elixir_ls/
Expand Down
46 changes: 46 additions & 0 deletions lib/mix/tasks/delegate/add_prc.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule Mix.Tasks.Delegate.AddPrc do
use Mix.Task

import Ecto.Query

alias Vae.Repo
alias Vae.Certification
alias Vae.Delegate
alias Vae.Rome

def run(_args) do
{:ok, _} = Application.ensure_all_started(:vae)

prcs = Delegate
|> preload(:certifiers)
|> where(is_prc: true)
|> Repo.all()

prcs_no_delegate = Enum.filter(prcs, fn %Delegate{certifiers: certifiers} -> length(certifiers) == 0 end)

Enum.each(prcs_no_delegate, &(Repo.delete(&1)))

File.stream!("priv/2023-07_list_prc.keep.csv")
|> CSV.decode!(headers: true, num_workers: 1)
|> Enum.each(fn %{
"Region" => region,
"DEPARTEMENT" => department,
"NOM" => name,
"Mandataire" => mandataire,
"ADRESSE" => address,
"TELEPHONE" => phone,
"Mail" => email
} ->
%Delegate{
is_active: true,
is_prc: true,
name: "#{name} - #{mandataire}",
administrative: region,
address: address,
telephone: phone,
email: email
}
|> Repo.insert!()
end)
end
end
Loading

0 comments on commit 29c1488

Please sign in to comment.