Skip to content

Commit

Permalink
feat: update logic to fill new fields (#545)
Browse files Browse the repository at this point in the history
* feat: update logic to fill new fields

* fix: missing await

* feat: add query limit & optional chaining

* feat: split process into a function + cli

* fix: remove import
  • Loading branch information
kevbarns authored Aug 21, 2023
1 parent 4ca418e commit b91db11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { checkAwaitingCompaniesValidation } from "./jobs/lba_recruteur/user/misc
import updateBrevoBlockedEmails from "./jobs/updateBrevoBlockedEmails/updateBrevoBlockedEmails.js"
import { importReferentielOnisep } from "./jobs/rdv/importReferentielOnisep.js"
import updateReferentielRncpRomes from "./jobs/referentielRncpRome/updateReferentielRncpRomes.js"
import { updateFormationCatalogue } from "./jobs/formationsCatalogue/updateFormationCatalogue.js"

cli.addHelpText("after", null)

Expand Down Expand Up @@ -262,6 +263,13 @@ cli
runScript(() => importCatalogueFormationJob())
})

cli
.command("sync-catalogue-trainings-extra-data")
.description("Mise à jour des champs spécifiques de la collection formations catalogue")
.action(() => {
runScript((components) => updateFormationCatalogue(components))
})

cli
.command("sync-sib-blocked")
.option("-all-addresses, [AllAddresses]", "pour récupérer toutes les adresses bloquées", false)
Expand Down
24 changes: 24 additions & 0 deletions server/src/jobs/formationsCatalogue/updateFormationCatalogue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { logger } from "../../common/logger.js"
import { FormationCatalogue } from "../../common/model/index.js"
import { IFormationCatalogue } from "../../common/model/schema/formationCatalogue/formationCatalogue.types.js"
import { asyncForEach } from "../../common/utils/asyncUtils.js"
import { getFormationsFromCatalogueMe } from "../../services/catalogue.service.js"

export const updateFormationCatalogue = async ({ db }) => {
logger.info("--- update formation catalogue data --- start")
const formations = await FormationCatalogue.find({ $and: [{ affelnet_statut: null }, { parcoursup_id: null }] }).lean()

logger.info(`${formations.length} à contrôler...`)

await asyncForEach(formations, async (formation: IFormationCatalogue) => {
const formationME = await getFormationsFromCatalogueMe({
limit: 1,
query: { cle_ministere_educatif: formation.cle_ministere_educatif },
select: { parcoursup_id: 1, affelnet_statut: 1 },
})
const { parcoursup_id, affelnet_statut } = formationME[0]

await db.collection("formationcatalogues").updateOne({ cle_ministere_educatif: formation.cle_ministere_educatif }, { $set: { parcoursup_id, affelnet_statut } })
})
logger.info("--- update formation catalogue data --- end")
}

0 comments on commit b91db11

Please sign in to comment.