Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ajout du code dispositif pour les offres en apprentissage #513

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/src/modules/import/fileTypes/Offres_apprentissage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const OffresApprentissageSchema = z
"Formation: code CFD": z.string(),
"Formation: niveau BCN": z.string(),
"Offre: Tags": z.string(),
"Formation: codes MEF": z.string().optional(),
"Formation: durée collectée": z.string().optional(),
})
.superRefine((data, ctx) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { inject } from "injecti";
import { MILLESIMES_IJ, RENTREES_SCOLAIRES } from "shared";

import { rawDataRepository } from "@/modules/import/repositories/rawData.repository";
import { getCfdDispositifs } from "@/modules/import/usecases/getCfdRentrees/getCfdDispositifs.dep";
import { getCfdRentrees } from "@/modules/import/usecases/getCfdRentrees/getCfdRentrees.usecase";
import { findDiplomesProfessionnels } from "@/modules/import/usecases/importIJData/findDiplomesProfessionnels.dep";
Expand All @@ -26,6 +27,56 @@ import {

const processedUais = new Set<string>();

const parseCfd = (mef: string, duree: number): number => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca mériterait d'avoir surement des tests pour être sur que le jour où on modifie ça ne casse rien, est ce qu'il y a un intérêt a remplacer les valeurs par des constantes ?

const threeFirstChars = parseInt(mef.substring(0, 3));

switch (threeFirstChars) {
case 320:
if (duree === 1) return 310;
if (duree === 2) return 311;
if (duree === 3) return 312;
return -1;

case 323:
if (duree === 1) return 370;
return -1;

case 400:
if (duree === 1 || duree === 2 || duree === 3) return 247;
return -1;

case 401:
if (duree === 3) return 252;
return -1;

case 403:
if (duree === 2) return 273;
return -1;

case 450:
if (duree === 1 || duree === 2 || duree === 3) return 890;
return -1;

case 500:
if (duree === 1) return 240;
if (duree === 2) return 241;
if (duree === 3) return 242;
return -1;

case 503:
if (duree === 1) return 270;
return -1;

case 561:
return 257;

case 461:
return 258;
}

return -1;
};

export const [importFormations] = inject(
{
importFormation,
Expand Down Expand Up @@ -87,10 +138,13 @@ export const [importFormationEtablissements] = inject(
importIndicateurSortieApprentissage,
importIndicateursRegionSortieApprentissage,
findUAIsApprentissage,
findRawData: rawDataRepository.findRawData,
findRawDatas: rawDataRepository.findRawDatas,
},
(deps) => {
return async ({ cfd, voie = "scolaire" }: { cfd: string; voie?: string }) => {
if (voie === "apprentissage") {
//console.log("codesDispo", 3);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

await deps.importIndicateursRegionSortieApprentissage({ cfd });
const uais = await deps.findUAIsApprentissage({ cfd });
if (!uais) return;
Expand All @@ -102,20 +156,63 @@ export const [importFormationEtablissements] = inject(
}
processedUais.add(uai);
}
const formationEtablissement = await deps.createFormationEtablissement({
uai,
cfd,
codeDispositif: null,
voie: "apprentissage",

// Récupération du codeDispositif pour les formations en apprentissage
// à partir du contenu du fichier offres_apprentissage
const offreApprentissage = await deps.findRawData({
type: "offres_apprentissage",
filter: { "Formation: code CFD": cfd },
});

for (const millesime of MILLESIMES_IJ) {
await deps.importIndicateurSortieApprentissage({
if (!offreApprentissage) continue;

const codesDispositifs: Array<string> = [];
const mefs = offreApprentissage["Formation: codes MEF"]?.split(",").map((mef) => mef.trim()) ?? [];
const dureeCollectee = offreApprentissage?.["Formation: durée collectée"]
? parseInt(offreApprentissage?.["Formation: durée collectée"])
: -1;

if (mefs.length > 0) {
/**
* Chercher ce MEF dans le fichier nMef le couple (FORMATION_DIPLOME, DISPOSITIF_FORMATION) qui correspond au (cfd, codeDispositif)
*/
for (const mef of mefs) {
const nMefs = await deps.findRawDatas({
type: "nMef",
filter: {
MEF: mef,
FORMATION_DIPLOME: cfd,
},
});

nMefs.forEach((nMef) => {
codesDispositifs.push(nMef.DISPOSITIF_FORMATION);
});
}
} else {
// déduire le code dispositif du cfd
const codeDispositif = parseCfd(offreApprentissage?.["Formation: code CFD"], dureeCollectee);
if (codeDispositif > -1) {
codesDispositifs.push(codeDispositif.toString());
}
}

for (const codeDispositif of codesDispositifs) {
const formationEtablissement = await deps.createFormationEtablissement({
uai,
formationEtablissementId: formationEtablissement.id,
millesime,
cfd,
codeDispositif,
voie: "apprentissage",
});

for (const millesime of MILLESIMES_IJ) {
await deps.importIndicateurSortieApprentissage({
uai,
formationEtablissementId: formationEtablissement.id,
millesime,
cfd,
});
}
}
}
} else {
Expand Down
Loading