Skip to content

Commit

Permalink
feat: mise a jour des donnees de transfert decaRaw vers effectifsDeca (
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrmr authored May 6, 2024
1 parent ada8e2f commit d9a8e2f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ exports[`validation-schema should create validation schema for decaRaw: decaRaw
"code_postal",
],
},
"courriel": {
"bsonType": "string",
},
"date_naissance": {
"anyOf": [
{
Expand Down Expand Up @@ -382,6 +385,9 @@ exports[`validation-schema should create validation schema for decaRaw: decaRaw
"sexe": {
"bsonType": "number",
},
"telephone": {
"bsonType": "string",
},
},
"required": [
"handicap",
Expand All @@ -392,6 +398,8 @@ exports[`validation-schema should create validation schema for decaRaw: decaRaw
"derniere_classe",
"nationalite",
"sexe",
"telephone",
"courriel",
],
},
"created_at": {
Expand Down
42 changes: 36 additions & 6 deletions server/src/jobs/hydrate/deca/hydrate-deca-raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { normalize } from "path";

import { captureException } from "@sentry/node";
import { ObjectId, WithoutId } from "mongodb";
import { IOrganisme } from "shared/models";
import { IEffectif, IOrganisme } from "shared/models";
import { IDecaRaw } from "shared/models/data/decaRaw.model";
import { zApprenant } from "shared/models/data/effectifs/apprenant.part";
import { zContrat } from "shared/models/data/effectifs/contrat.part";
import { IEffectifDECA } from "shared/models/data/effectifsDECA.model";
import { zodOpenApi } from "shared/models/zodOpenApi";
import { cyrb53Hash, getYearFromDate } from "shared/utils";

import { addComputedFields } from "@/common/actions/effectifs.actions";
Expand Down Expand Up @@ -64,10 +67,22 @@ async function transformDocument(document: IDecaRaw): Promise<WithoutId<IEffecti
date_debut_contrat,
date_fin_contrat,
date_effet_rupture,
type_contrat,
} = document;
const { nom, prenom, date_naissance } = alternant;
const {
nom,
prenom,
date_naissance,
handicap,
telephone,
sexe,
nationalite,
courriel,
adresse: adresseAlternant,
derniere_classe,
} = alternant;
const { date_debut_formation, date_fin_formation, code_diplome, rncp, intitule_ou_qualification } = formation;
const { siret, denomination, naf, adresse } = employeur;
const { siret, denomination, naf, adresse, nombre_de_salaries } = employeur;
const { uai_cfa, siret: orgSiret } = organisme_formation;

const startYear = getYearFromDate(date_debut_formation);
Expand All @@ -87,25 +102,38 @@ async function transformDocument(document: IDecaRaw): Promise<WithoutId<IEffecti
throw new Error("Les dates de début et de fin de contrat sont requises");
}

const effectif = {
const effectif: IEffectifDECA = {
_id: new ObjectId(),
deca_raw_id: document._id,
apprenant: {
nom,
prenom,
date_de_naissance: date_naissance,
nationalite: nationalite as zodOpenApi.TypeOf<typeof zApprenant>["nationalite"],
historique_statut: [],
has_nir: false,
rqth: handicap,
sexe: sexe === 1 ? "M" : sexe === 0 ? "F" : null,
telephone,
courriel,
adresse: {
numero: adresseAlternant.numero ? parseInt(adresseAlternant.numero, 10) : undefined,
voie: adresseAlternant.voie,
code_postal: adresseAlternant.code_postal,
},
situation_avant_contrat: derniere_classe as zodOpenApi.TypeOf<typeof zApprenant>["situation_avant_contrat"],
},
contrats: [
{
siret,
denomination,
type_employeur: null,
type_employeur: parseInt(type_contrat, 10) as zodOpenApi.TypeOf<typeof zContrat>["type_employeur"],
naf,
adresse: { code_postal: adresse.code_postal },
date_debut: date_debut_contrat,
date_fin: date_fin_contrat,
date_rupture: date_effet_rupture,
nombre_de_salaries,
},
],
formation: {
Expand All @@ -119,6 +147,8 @@ async function transformDocument(document: IDecaRaw): Promise<WithoutId<IEffecti
date_fin: date_fin_formation,
},
organisme_id: organisme._id,
organisme_responsable_id: organisme._id,
organisme_formateur_id: organisme._id,
validation_errors: [],
created_at: new Date(),
updated_at: new Date(),
Expand All @@ -129,7 +159,7 @@ async function transformDocument(document: IDecaRaw): Promise<WithoutId<IEffecti

return {
...effectif,
_computed: addComputedFields({ organisme, effectif }),
_computed: addComputedFields({ organisme, effectif: effectif as IEffectif }),
is_deca_compatible: !organisme.is_transmission_target,
};
}
2 changes: 2 additions & 0 deletions shared/models/data/decaRaw.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const zAlternant = z.object({
derniere_classe: z.number(),
nationalite: z.number(),
sexe: z.number(),
telephone: z.string(),
courriel: z.string(),
});

const zEmployeur = z.object({
Expand Down
1 change: 1 addition & 0 deletions shared/models/data/effectifsDECA.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const zEffectifComputedStatut = z.object({

export const zEffectifDECA = z.object({
_id: zObjectId.describe("Identifiant MongoDB de l'effectifDeca"),
deca_raw_id: zObjectId.describe("Identifiant decaraw associé à cet effectif"),
organisme_id: zObjectId.describe("Organisme id (lieu de formation de l'apprenant pour la v3)"),
organisme_responsable_id: zObjectId.describe("Organisme responsable id").nullish(),
organisme_formateur_id: zObjectId.describe("Organisme formateur id").nullish(),
Expand Down

0 comments on commit d9a8e2f

Please sign in to comment.