diff --git a/server/src/modules/data/usecases/getFormations/deps/getFormationsQuery.dep.ts b/server/src/modules/data/usecases/getFormations/deps/getFormationsQuery.dep.ts index eda0ec533..1b7deca7e 100644 --- a/server/src/modules/data/usecases/getFormations/deps/getFormationsQuery.dep.ts +++ b/server/src/modules/data/usecases/getFormations/deps/getFormationsQuery.dep.ts @@ -111,6 +111,11 @@ export const getFormationsQuery = async ({ ) .end() .as("positionQuadrant"), + isFormationActionPrioritaire({ + cfdRef: "formationEtablissement.cfd", + codeDispositifRef: "formationEtablissement.codeDispositif", + codeRegionRef: "etablissement.codeRegion", + }).as(TypeFormationSpecifiqueEnum["Action prioritaire"]), ]) .$call((eb) => { if (!positionQuadrant) return eb; @@ -209,11 +214,6 @@ export const getFormationsQuery = async ({ else null end `.as("dateFermeture"), - isFormationActionPrioritaire({ - cfdRef: "formationEtablissement.cfd", - codeDispositifRef: "formationEtablissement.codeDispositif", - codeRegionRef: "etablissement.codeRegion", - }).as(TypeFormationSpecifiqueEnum["Action prioritaire"]), eb.ref("formationView.isTransitionDemographique").as(TypeFormationSpecifiqueEnum["Transition démographique"]), eb.ref("formationView.isTransitionEcologique").as(TypeFormationSpecifiqueEnum["Transition écologique"]), eb.ref("formationView.isTransitionNumerique").as(TypeFormationSpecifiqueEnum["Transition numérique"]), @@ -361,6 +361,7 @@ export const getFormationsQuery = async ({ } return q; }) + .$narrowType<{ ["Action prioritaire"]: boolean }>() .orderBy("libelleFormation", "asc") .orderBy("libelleNiveauDiplome", "asc") .orderBy("libelleDispositif", "asc") @@ -376,7 +377,13 @@ export const getFormationsQuery = async ({ formations: result.map((formation) => ({ ...formation, isFormationRenovee: !!formation.isFormationRenovee, - formationSpecifique: formatFormationSpecifique(formation), + formationSpecifique: formatFormationSpecifique({ + ...formation, + [TypeFormationSpecifiqueEnum["Action prioritaire"]]: + TypeFormationSpecifiqueEnum["Action prioritaire"] in formation + ? !!formation[TypeFormationSpecifiqueEnum["Action prioritaire"]] + : false, + }), })), }; }; diff --git a/server/src/modules/demandes/usecases/getDemande/getDemande.query.ts b/server/src/modules/demandes/usecases/getDemande/getDemande.query.ts index 1ace16c50..86cda2ea5 100644 --- a/server/src/modules/demandes/usecases/getDemande/getDemande.query.ts +++ b/server/src/modules/demandes/usecases/getDemande/getDemande.query.ts @@ -53,13 +53,13 @@ export const getDemandeQuery = async ({ numero, user }: Filters) => { ), formation: jsonObjectFrom( eb - .selectFrom("formationView") - .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "formationView.codeNiveauDiplome") + .selectFrom("dataFormation") + .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "dataFormation.codeNiveauDiplome") .select((ebDataFormation) => [ - sql`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")}, + sql`CONCAT(${ebDataFormation.ref("dataFormation.libelleFormation")}, ' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')', - ' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"), - sql`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( + ' (',${ebDataFormation.ref("dataFormation.cfd")},')')`.as("libelleFormation"), + sql`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( "isFCIL" ), ]) @@ -73,11 +73,11 @@ export const getDemandeQuery = async ({ numero, user }: Filters) => { .onRef(sql`"data"->>'DISPOSITIF_FORMATION'`, "=", "dispositif.codeDispositif") .on("rawData.type", "=", "nMef") ) - .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "formationView.cfd") + .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "dataFormation.cfd") .distinctOn("codeDispositif") ).as("dispositifs") ) - .whereRef("formationView.cfd", "=", "demande.cfd") + .whereRef("dataFormation.cfd", "=", "demande.cfd") .limit(1) ), etablissementCompensation: jsonObjectFrom( @@ -89,13 +89,13 @@ export const getDemandeQuery = async ({ numero, user }: Filters) => { ), formationCompensation: jsonObjectFrom( eb - .selectFrom("formationView") - .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "formationView.codeNiveauDiplome") + .selectFrom("dataFormation") + .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "dataFormation.codeNiveauDiplome") .select((ebDataFormation) => [ - sql`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")}, + sql`CONCAT(${ebDataFormation.ref("dataFormation.libelleFormation")}, ' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')', - ' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"), - sql`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( + ' (',${ebDataFormation.ref("dataFormation.cfd")},')')`.as("libelleFormation"), + sql`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( "isFCIL" ), ]) @@ -109,11 +109,11 @@ export const getDemandeQuery = async ({ numero, user }: Filters) => { .onRef(sql`"data"->>'DISPOSITIF_FORMATION'`, "=", "dispositif.codeDispositif") .on("rawData.type", "=", "nMef") ) - .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "formationView.cfd") + .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "dataFormation.cfd") .distinctOn("codeDispositif") ).as("dispositifs") ) - .whereRef("formationView.cfd", "=", "demande.compensationCfd") + .whereRef("dataFormation.cfd", "=", "demande.compensationCfd") .limit(1) ), }).as("metadata"), @@ -168,22 +168,24 @@ export const getDemandeQuery = async ({ numero, user }: Filters) => { demande.metadata.formation?.dispositifs.find((item) => item.codeDispositif === demande?.codeDispositif) ?.codeDispositif; - return { - ...demande, - metadata: { - ...demande.metadata, - formation: demande.metadata.formation, - etablissement: demande.metadata.etablissement, - formationCompensation: demande.metadata.formationCompensation, - etablissementCompensation: demande.metadata.etablissementCompensation, - }, - statut: castDemandeStatutWithoutSupprimee(demande.statut), - createdAt: demande.createdAt?.toISOString(), - updatedAt: demande.updatedAt?.toISOString(), - campagne: { - ...demande.campagne, - }, - codeDispositif, - formationSpecifique: formatFormationSpecifique(demande), - }; + return ( + demande && { + ...demande, + metadata: { + ...demande.metadata, + formation: demande.metadata.formation, + etablissement: demande.metadata.etablissement, + formationCompensation: demande.metadata.formationCompensation, + etablissementCompensation: demande.metadata.etablissementCompensation, + }, + statut: castDemandeStatutWithoutSupprimee(demande.statut), + createdAt: demande.createdAt?.toISOString(), + updatedAt: demande.updatedAt?.toISOString(), + campagne: { + ...demande.campagne, + }, + codeDispositif, + formationSpecifique: formatFormationSpecifique(demande), + } + ); }; diff --git a/server/src/modules/intentions/usecases/getIntention/getIntention.query.ts b/server/src/modules/intentions/usecases/getIntention/getIntention.query.ts index 1faba9eb9..9ecd2575b 100644 --- a/server/src/modules/intentions/usecases/getIntention/getIntention.query.ts +++ b/server/src/modules/intentions/usecases/getIntention/getIntention.query.ts @@ -78,13 +78,19 @@ export const getIntentionQuery = async ({ numero, user }: Filters) => { ), formation: jsonObjectFrom( eb - .selectFrom("formationView") - .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "formationView.codeNiveauDiplome") + .selectFrom("dataFormation") + .leftJoin("niveauDiplome", "niveauDiplome.codeNiveauDiplome", "dataFormation.codeNiveauDiplome") .select((ebDataFormation) => [ - sql`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")}, - ' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')', - ' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"), - sql`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( + sql`CONCAT( + ${ebDataFormation.ref("formationView.libelleFormation")}, + ' (', + ${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")}, + ')', + ' (', + ${ebDataFormation.ref("dataFormation.cfd")}, + ')') + `.as("libelleFormation"), + sql`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as( "isFCIL" ), ]) @@ -98,11 +104,11 @@ export const getIntentionQuery = async ({ numero, user }: Filters) => { .onRef(sql`"data"->>'DISPOSITIF_FORMATION'`, "=", "dispositif.codeDispositif") .on("rawData.type", "=", "nMef") ) - .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "formationView.cfd") + .whereRef(sql`"data"->>'FORMATION_DIPLOME'`, "=", "dataFormation.cfd") .distinctOn("codeDispositif") ).as("dispositifs") ) - .whereRef("formationView.cfd", "=", "intention.cfd") + .whereRef("dataFormation.cfd", "=", "intention.cfd") .limit(1) ), }).as("metadata"), diff --git a/server/src/modules/utils/formatFormationSpecifique.ts b/server/src/modules/utils/formatFormationSpecifique.ts index d8959de9f..edde8cefe 100644 --- a/server/src/modules/utils/formatFormationSpecifique.ts +++ b/server/src/modules/utils/formatFormationSpecifique.ts @@ -2,7 +2,7 @@ import type { TypeFormationSpecifiqueType } from "shared/enum/formationSpecifiqu import { TypeFormationSpecifiqueEnum } from "shared/enum/formationSpecifiqueEnum"; export const formatFormationSpecifique = ( - formation: Record + formation: Record, string | boolean | undefined | null> ) => ({ [TypeFormationSpecifiqueEnum["Action prioritaire"]]: TypeFormationSpecifiqueEnum["Action prioritaire"] in formation