-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update logic to fill new fields (#545)
* 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
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
server/src/jobs/formationsCatalogue/updateFormationCatalogue.ts
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,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") | ||
} |