-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
scripts/taux-de-penetration/ajout_agences_milo_sans_conseiller_cej.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { Sequelize } = require('sequelize') | ||
const sequelize = new Sequelize( | ||
'postgresql://passemploi:passemploi@localhost:55432/passemploidb', | ||
{ | ||
dialect: 'postgres' | ||
} | ||
) | ||
|
||
const referentiel_agences_milo = require('./referentiel_agences_api_milo_copy.json') | ||
|
||
async function execute() { | ||
const [agencesCej, _metadata] = await sequelize.query(` | ||
SELECT * | ||
FROM agence | ||
WHERE structure = 'MILO' | ||
AND id != '9999' | ||
`) | ||
|
||
let agencesNonCejReferentiel = await recupererLesAgencesSansConseillersCej(agencesCej) | ||
ajouterLesInformationsGeographiques(agencesNonCejReferentiel, agencesCej) | ||
/*await persisterLesAgencesSansConseillersCej(agencesNonCejReferentiel) | ||
* await persisterLeNomUsuelDansLesAgencesCej*/ | ||
console.log(agencesNonCejReferentiel) | ||
} | ||
|
||
execute() | ||
|
||
async function recupererLesAgencesSansConseillersCej(agencesCej) { | ||
return referentiel_agences_milo | ||
.map(agenceMilo => { | ||
return { | ||
id: agenceMilo.codeStructure, | ||
nom_officiel: agenceMilo.nomOfficiel, | ||
nom_usuel: agenceMilo.nomUsuel | ||
} | ||
}) | ||
.filter( | ||
agenceMilo => !agencesCej.map(agence => agence.id).includes(agenceMilo.id) | ||
) | ||
} | ||
|
||
function ajouterLesInformationsGeographiques(agencesNonCejReferentiel,agencesCej) { | ||
for(let agenceNonCej of agencesNonCejReferentiel) { | ||
const departement = agenceNonCej.adresse.codePostal.slice(0,2) | ||
if(agenceCejTrouvee) { | ||
|
||
} else { | ||
|
||
} | ||
agencesCej.find - même département | ||
màj agence pour ajouter infos département et région, timezone | ||
} | ||
} | ||
|
||
/* | ||
async function persisterLesAgencesSansConseillersCej(agencesNonCejReferentiel) { | ||
await sequelize.transaction(async transaction => { | ||
await sequelize.query(` | ||
INSERT INTO agence | ||
VALUES | ||
`, { | ||
transaction | ||
}) | ||
await sequelize.query(` | ||
INSERT INTO structure_milo | ||
VALUES | ||
`, { | ||
transaction | ||
}) | ||
}) | ||
}*/ |