Skip to content

Commit

Permalink
fix: mise a jour des donnees indicateurs organismes (#3809)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Gaucher <[email protected]>
  • Loading branch information
Pomarom and Pomarom authored Aug 14, 2024
1 parent b07ac73 commit 7a6bb4b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 16 deletions.
12 changes: 8 additions & 4 deletions server/src/common/actions/indicateurs/indicateurs.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,18 +783,22 @@ async function getOrganismeRestriction(organismeId?: ObjectId) {

export const getIndicateursForRelatedOrganismes = async (organismeId: ObjectId, indicateurType: string) => {
const org = await organismesDb().findOne({ _id: organismeId });
const organismesFormateurs = org?.organismesFormateurs;

if (!organismesFormateurs) {
return [];
}
switch (indicateurType) {
case ORGANISME_INDICATEURS_TYPE.SANS_EFFECTIFS:
return org?.organismesFormateurs?.filter(
return organismesFormateurs.filter(
({ last_transmission_date }) => !hasRecentTransmissions(last_transmission_date)
);
case ORGANISME_INDICATEURS_TYPE.NATURE_INCONNUE:
return org?.organismesFormateurs?.filter(({ nature }) => nature === "inconnue");
return organismesFormateurs.filter(({ nature }) => nature === "inconnue");
case ORGANISME_INDICATEURS_TYPE.SIRET_FERME:
return org?.organismesFormateurs?.filter(({ ferme }) => !!ferme);
return organismesFormateurs.filter(({ ferme }) => !!ferme);
case ORGANISME_INDICATEURS_TYPE.UAI_NON_DETERMINE:
return org?.organismesFormateurs?.filter(({ uai }) => !uai);
return organismesFormateurs.filter(({ uai }) => !uai);
default:
return [];
}
Expand Down
13 changes: 12 additions & 1 deletion server/src/common/actions/telechargementListeNomLogs.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { ObjectId } from "mongodb";
import { telechargementListesNominativesLogsDb } from "@/common/model/collections";

export const createTelechargementListeNomLog = async (
type: "apprenant" | "apprenti" | "inscritSansContrat" | "rupturant" | "abandon" | "inconnu" | "affelnet",
type:
| "apprenant"
| "apprenti"
| "inscritSansContrat"
| "rupturant"
| "abandon"
| "inconnu"
| "affelnet"
| "organismes_sans_effectifs"
| "organismes_nature_inconnue"
| "organismes_siret_ferme"
| "organismes_uai_non_determine",
elementList: string[],
date: Date,
userId: ObjectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12810,6 +12810,10 @@ exports[`validation-schema should create validation schema for telechargementLis
"rupturant",
"abandon",
"inconnu",
"organismes_sans_effectifs",
"organismes_nature_inconnue",
"organismes_siret_ferme",
"organismes_uai_non_determine",
"affelnet",
],
},
Expand Down
19 changes: 17 additions & 2 deletions server/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import express, { Application } from "express";
import Joi from "joi";
import { ObjectId } from "mongodb";
import passport from "passport";
import { typesEffectifNominatif, CODE_POSTAL_REGEX, zEffectifArchive, SOURCE_APPRENANT } from "shared";
import {
typesEffectifNominatif,
CODE_POSTAL_REGEX,
zEffectifArchive,
SOURCE_APPRENANT,
typesOrganismesIndicateurs,
} from "shared";
import swaggerUi from "swagger-ui-express";
import { z } from "zod";

Expand Down Expand Up @@ -531,7 +537,16 @@ function setupRoutes(app: Application) {
.get(
"/indicateurs/organismes/:type",
returnResult(async (req, res) => {
return await getIndicateursForRelatedOrganismes(res.locals.organismeId, req.params.type);
const indicateurs = await getIndicateursForRelatedOrganismes(res.locals.organismeId, req.params.type);
const type = await z.enum(typesOrganismesIndicateurs).parseAsync(req.params.type);
await createTelechargementListeNomLog(
`organismes_${type}`,
indicateurs.map(({ _id }) => (_id ? _id.toString() : "")),
new Date(),
req.user._id,
res.locals.organismeId
);
return indicateurs;
})
)
.get(
Expand Down
16 changes: 16 additions & 0 deletions shared/constants/indicateurs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ export const typesEffectifNominatif = [
] as const;

export type TypeEffectifNominatif = (typeof typesEffectifNominatif)[number];

export const ORGANISME_INDICATEURS_TYPE = {
SANS_EFFECTIFS: "sans_effectifs",
NATURE_INCONNUE: "nature_inconnue",
SIRET_FERME: "siret_ferme",
UAI_NON_DETERMINE: "uai_non_determine",
};

export const typesOrganismesIndicateurs = [
ORGANISME_INDICATEURS_TYPE.SANS_EFFECTIFS as "sans_effectifs",
ORGANISME_INDICATEURS_TYPE.NATURE_INCONNUE as "nature_inconnue",
ORGANISME_INDICATEURS_TYPE.SIRET_FERME as "siret_ferme",
ORGANISME_INDICATEURS_TYPE.UAI_NON_DETERMINE as "uai_non_determine",
] as const;

export type TypeOrganismesIndicateurs = (typeof typesOrganismesIndicateurs)[number];
7 changes: 0 additions & 7 deletions shared/models/data/organismes.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ export const UAI_INCONNUE = "non déterminée";
export const UAI_INCONNUE_TAG_FORMAT = UAI_INCONNUE.toUpperCase();
export const UAI_INCONNUE_CAPITALIZE = `${UAI_INCONNUE.charAt(0).toUpperCase()}${UAI_INCONNUE.slice(1)}`;

export const ORGANISME_INDICATEURS_TYPE = {
SANS_EFFECTIFS: "SANS_EFFECTIFS",
NATURE_INCONNUE: "NATURE_INCONNUE",
SIRET_FERME: "SIRET_FERME",
UAI_NON_DETERMINE: "UAI_NON_DETERMINE",
};

const relationOrganismeSchema = z
.object({
// infos référentiel
Expand Down
8 changes: 6 additions & 2 deletions shared/models/data/telechargementListesNomLogs.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import type { CreateIndexesOptions, IndexSpecification } from "mongodb";
import { z } from "zod";
import { zObjectId } from "zod-mongodb-schema";

import { typesEffectifNominatif } from "../../constants";
import { typesEffectifNominatif, typesOrganismesIndicateurs } from "../../constants";

const collectionName = "telechargementListeNomLogs";

const indexes: [IndexSpecification, CreateIndexesOptions][] = [];

const extendedTypesEffectifNominatif = [...typesEffectifNominatif, "affelnet"] as const;
export const extendedTypesEffectifNominatif = [
...typesEffectifNominatif,
...typesOrganismesIndicateurs.map((type) => `organismes_${type}`),
"affelnet",
] as const;

export const zTelechargementListeNomLogs = z.object({
_id: zObjectId.describe("Identifiant MongoDB du log"),
Expand Down

0 comments on commit 7a6bb4b

Please sign in to comment.