Skip to content

Commit

Permalink
feat: WIP - prise en compte des ml dans le process ingestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomarom committed Dec 17, 2024
1 parent 8891111 commit d3cfc7a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/src/common/actions/effectifs.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export const buildEffectifForMissionLocale = (
courriel: effectif.apprenant.courriel,
rqth: effectif.apprenant.rqth,
},
parcours: effectif._computed?.statut,
statut: effectif._computed?.statut,
formation: effectif.formation,
organisme: effectif._computed?.organisme,
user: {
Expand Down
21 changes: 15 additions & 6 deletions server/src/common/actions/effectifs/effectifs.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ export const getDetailedEffectifById = async (_id: any) => {
};

export const getPaginatedEffectifsByMissionLocaleId = async (
missionLocaleId: string,
missionLocaleId: number,
page: number = 1,
limit: number = 20
) => {
const aggregation = [
{
$match: {
"_computed.missionLocale.id": missionLocaleId,
"apprenant.adresse.mission_locale_id": missionLocaleId,
annee_scolaire: { $in: getAnneesScolaireListFromDate(new Date()) },
},
},
Expand Down Expand Up @@ -184,12 +184,21 @@ export const getPaginatedEffectifsByMissionLocaleId = async (
data: [{ $skip: (page - 1) * limit }, { $limit: limit }],
},
},
{ $unwind: { path: "$pagination" } },
{ $unwind: { path: "$pagination", preserveNullAndEmptyArrays: true } },
];
const { pagination, data } = (await effectifsDb().aggregate(aggregation).next()) as {

const result = (await effectifsDb().aggregate(aggregation).next()) as {
pagination: any;
data: Array<IEffectif & { organisation: IOrganisation } & { cfa_users: IUsersMigration }>;
};
const effectifs = data.map((effectif) => buildEffectifForMissionLocale(effectif));
return { pagination, data: effectifs };

if (!result) {
return { pagination: { total: 0, page, limit }, data: [] };
}

if (result.pagination) {
result.pagination.lastPage = Math.ceil(result.pagination.total / limit);
}
result.data = result.data.map((effectif) => buildEffectifForMissionLocale(effectif));
return result;
};
1 change: 1 addition & 0 deletions server/src/common/actions/engine/engine.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const completeEffectifAddress = async <T extends { apprenant: Partial<IEf
departement: communeInfo.departement.codeInsee,
academie: communeInfo.academie.code,
region: communeInfo.region.codeInsee,
mission_locale_id: communeInfo.mission_locale?.id,
});

return effectifDataWithAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { DateFilters } from "../helpers/filters";

import { buildIndicateursEffectifsPipeline } from "./indicateurs.actions";

export const getEffectifIndicateursForMissionLocaleId = async (filters: DateFilters, missionLocaleId: string) => {
export const getEffectifIndicateursForMissionLocaleId = async (filters: DateFilters, missionLocaleId: number) => {
const aggregation = [
{
$match: {
"_computed.missionLocale.id": missionLocaleId,
"apprenant.adresse.mission_locale_id": missionLocaleId,
},
},
...buildIndicateursEffectifsPipeline(null, filters.date),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from "express";
import { IOrganisationMissionLocale } from "shared/models";

import { getPaginatedEffectifsByMissionLocaleId } from "@/common/actions/effectifs/effectifs.actions";
import { dateFiltersSchema } from "@/common/actions/helpers/filters";
Expand All @@ -14,12 +15,12 @@ export default () => {
};

const getIndicateursMissionLocale = async (req, { locals }) => {
const { missionLocale } = locals;
const missionLocale = locals.missionLocale as IOrganisationMissionLocale;
const filters = await validateFullZodObjectSchema(req.query, dateFiltersSchema);
return await getEffectifIndicateursForMissionLocaleId(filters, missionLocale._id.toString());
return await getEffectifIndicateursForMissionLocaleId(filters, missionLocale.ml_id);
};

const getEffectifsMissionLocale = async (_req, { locals }) => {
const { missionLocale } = locals;
return await getPaginatedEffectifsByMissionLocaleId(missionLocale._id.toString());
const missionLocale = locals.missionLocale as IOrganisationMissionLocale;
return await getPaginatedEffectifsByMissionLocaleId(missionLocale.ml_id);
};
8 changes: 1 addition & 7 deletions shared/models/data/effectifs.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ const indexes: [IndexSpecification, CreateIndexesOptions][] = [
[{ "_computed.organisme.fiable": 1, annee_scolaire: 1 }, {}],
[{ "_computed.formation.codes_rome": 1 }, {}],
[{ "_computed.formation.opcos": 1 }, {}],
[{ "_computed.missionLocale.id": 1 }, {}],
];

const StatutApprenantEnum = zodEnumFromArray(
STATUT_APPRENANT_VALUES as (typeof STATUT_APPRENANT)[keyof typeof STATUT_APPRENANT][]
);

const zEffectifComputedStatut = z.object({
export const zEffectifComputedStatut = z.object({
en_cours: StatutApprenantEnum,
parcours: z.array(
z.object({
Expand All @@ -104,10 +103,6 @@ const zEffectifComputedStatut = z.object({
),
});

const zEffectifComputedMissionLocale = z.object({
id: z.string(),
});

export const zEffectif = z.object({
_id: zObjectId.describe("Identifiant MongoDB de l'effectif"),
organisme_id: zObjectId.describe("Organisme id (lieu de formation de l'apprenant pour la v3)"),
Expand Down Expand Up @@ -232,7 +227,6 @@ export const zEffectif = z.object({
.nullish(),
// @TODO: nullish en attendant la migration et passage en nullable ensuite (migration: 20240305085918-effectifs-types.ts)
statut: zEffectifComputedStatut.nullish(),
missionLocale: zEffectifComputedMissionLocale.nullish(),
},
{
description: "Propriétés calculées ou récupérées d'autres collections",
Expand Down
1 change: 1 addition & 0 deletions shared/models/parts/adresseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ export const zAdresse = zodOpenApi.object({
description: "Code Bassin d'emploi",
})
.optional(),
mission_locale_id: zodOpenApi.number({ description: "Id de mission locale" }).optional(),
});
21 changes: 21 additions & 0 deletions shared/models/routes/mission-locale/MissionLocaleEffectif.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { z } from "zod";
import { zObjectId } from "zod-mongodb-schema";

import { zEffectif, zEffectifComputedStatut } from "../../data";
import { zApprenant } from "../../data/effectifs/apprenant.part";
import { zFormationEffectif } from "../../data/effectifs/formation.part";

const zEffectifMissionLocale = z.object({
_id: zObjectId,
apprenant: zApprenant.pick({
nom: true,
prenom: true,
date_de_naissance: true,
adresse: true,
telephone: true,
courriel: true,
rqth: true,
}),
statut: zEffectifComputedStatut,
formation: zFormationEffectif,
});

0 comments on commit d3cfc7a

Please sign in to comment.