Skip to content

Commit

Permalink
Merge pull request #501 from mission-apprentissage/fix/offres_apprent…
Browse files Browse the repository at this point in the history
…issage

fix: modification du format des offres apprentissage
  • Loading branch information
FaXaq authored Dec 16, 2024
2 parents 37be1aa + ffc6cc4 commit db3e04d
Show file tree
Hide file tree
Showing 8 changed files with 58,666 additions and 61,348 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ fileignoreconfig:
checksum: 28cdc80f0d836857ee9a802bff5a72a3ff3addad70a31b1ad4b7e98bc8db447c
- filename: server/src/modules/core/usecases/redirectDne/redirectDne.test.ts
checksum: 97116750d964c12ae4a0ffe9f5477d66526bf2f2e8ac8719ee399dc88faf7ae5
- filename: server/static/files/offres_apprentissage.csv
checksum: f8e173f11056708d2958e4f000428c2acb2281d9f19db55d9d72c5790bf0bf4b
- filename: server/tests/test_origin/controllers/campagnes.controller.test.js_old
checksum: 546c306130034fdce2c4165b1f31656dfa883bc8808f0e8b1fa5a5461da1cb08
- filename: server/tests/test_origin/controllers/users.controller.test.js_old
Expand Down
22 changes: 11 additions & 11 deletions server/src/modules/import/fileTypes/Offres_apprentissage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { z } from "zod";

export const OffresApprentissageSchema = z
.object({
"UAI formation": z.string().optional(),
"UAI Responsable": z.string().optional(),
"UAI formateur": z.string().optional(),
"Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)": z.string(),
"Niveau de la formation": z.string(),
Tags: z.string(),
"Lieu: UAI": z.string().optional(),
"Responsable: UAI": z.string().optional(),
"Formateur: UAI": z.string().optional(),
"Formation: code CFD": z.string(),
"Formation: niveau BCN": z.string(),
"Offre: Tags": z.string(),
})
.superRefine((data, ctx) => {
if (
typeof data["UAI formation"] === "undefined" &&
typeof data["UAI formateur"] === "undefined" &&
typeof data["UAI Responsable"] === "undefined"
typeof data["Lieu: UAI"] === "undefined" &&
typeof data["Formateur: UAI"] === "undefined" &&
typeof data["Responsable: UAI"] === "undefined"
) {
ctx.addIssue({
code: z.ZodIssueCode.invalid_type,
message: "UAI formation or UAI formateur or UAI Responsable Required",
path: ["UAI formation", "UAI formateur", "UAI Responsable"],
message: "'Lieu: UAI' or 'Formateur: UAI' or 'Responsable: UAI' Required",
path: ["Lieu: UAI", "Formateur: UAI", "Responsable: UAI"],
expected: "string",
received: "undefined",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const formatCFDDiplomeProfessionnel = (line: DiplomeProfessionnelLine) => {
};

const formatCFDOffreApprentissage = (line: Offres_apprentissage) => {
if (!line["Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)"]) return;
const cfd = line["Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)"];
if (!line["Formation: code CFD"]) return;
const cfd = line["Formation: code CFD"];

if (isNaN(parseInt(cfd))) return;
return cfd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ export const findUAIsApprentissage = async ({ cfd }: { cfd: string }) => {
.findRawDatas({
type: "offres_apprentissage",
filter: {
"Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)": cfd,
"Formation: code CFD": cfd,
},
})
.then((rawDatas) => {
if (!rawDatas || !rawDatas.length) return;
return rawDatas
.filter((rawData) => rawData["Tags"].includes("2023") || rawData["Tags"].includes("2024"))
.filter((rawData) => rawData["Offre: Tags"].includes("2023") || rawData["Offre: Tags"].includes("2024"))
.map((rawData) => {
if (rawData["UAI formation"]) return rawData["UAI formation"];
if (rawData["UAI formateur"]) return rawData["UAI formateur"];
return rawData["UAI Responsable"]!;
if (rawData["Lieu: UAI"]) return rawData["Lieu: UAI"];
if (rawData["Formateur: UAI"]) return rawData["Formateur: UAI"];
return rawData["Responsable: UAI"]!;
})
.filter((uai) => uai);
});
Expand All @@ -27,7 +27,7 @@ export const findUAIsApprentissage = async ({ cfd }: { cfd: string }) => {
// .where(
// "data",
// "@>",
// sql`{"Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)": ${cfd}}`
// sql`{"Formation: code CFD": ${cfd}}`
// )
// .where((eb) =>
// eb.and([
Expand All @@ -43,7 +43,7 @@ export const findUAIsApprentissage = async ({ cfd }: { cfd: string }) => {
// eb(
// "data",
// "@>",
// sql`{"Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)": ${cfd}}`
// sql`{"Formation: code CFD": ${cfd}}`
// ),
// ])
// )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ export const findUAIsApprentissage = async ({ cfd }: { cfd: string }) => {
.findRawDatas({
type: "offres_apprentissage",
filter: {
"Code du diplome ou du titre suivant la nomenclature de l'Education nationale (CodeEN)": cfd,
"Formation: code CFD": cfd,
},
})
.then((rawDatas) => {
if (!rawDatas || !rawDatas.length) return;
return rawDatas
.map((rawData) => {
if (rawData["UAI formation"]) return rawData["UAI formation"];
if (rawData["UAI formateur"]) return rawData["UAI formateur"];
return rawData["UAI Responsable"]!;
if (rawData["Lieu: UAI"]) return rawData["Lieu: UAI"];
if (rawData["Formateur: UAI"]) return rawData["Formateur: UAI"];
return rawData["Responsable: UAI"]!;
})
.filter((uai) => uai);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getKbdClient } from "@/db/db";

export type RawData = { type: string; data: JSON };
export type RawDataLine = { [key: string]: string };
export type RawData = { type: string; data: RawDataLine };

export const createRawDatas = async ({ data }: { data: Array<RawData> }) => {
return await getKbdClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@ import batchCreate from "@/modules/import/utils/batchCreate";
import { getStreamParser } from "@/modules/import/utils/parse";
import { verifyFileEncoding } from "@/modules/import/utils/verifyFileEncoding";

import type { RawDataLine } from "./createRawDatas.dep";
import { createRawDatas } from "./createRawDatas.dep";
import { deleteRawData } from "./deleteRawData.dep";

const sanitizeLine = (line: RawDataLine): RawDataLine => {
const sanitizedLine: RawDataLine = {};

Object.entries(line).map(([key, value]) => {
if (value.startsWith('"') && value.endsWith('"')) {
sanitizedLine[key] = value.slice(1, -1);
} else {
sanitizedLine[key] = value;
}
});

return sanitizedLine;
};

export enum ImportFileErrorType {
FILE = "file",
LINE = "line",
Expand Down Expand Up @@ -78,7 +93,7 @@ export const [importRawFile, importRawFileFactory] = inject(
line: count,
});
}
await deps.batch.create({ data: { data: line, type } });
await deps.batch.create({ data: { data: sanitizeLine(line), type } });
process.stdout.write(`Ajout de ${count} lignes\r`);
callback();
},
Expand Down
Loading

0 comments on commit db3e04d

Please sign in to comment.