Skip to content

Commit

Permalink
Merge pull request #514 from mission-apprentissage/fix/mep-19-12
Browse files Browse the repository at this point in the history
fix: metadata formation + formation spécifique console
  • Loading branch information
LucasDetre authored Dec 19, 2024
2 parents d1aa7f7 + a7d0b86 commit 03d884f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -361,6 +361,7 @@ export const getFormationsQuery = async ({
}
return q;
})
.$narrowType<{ ["Action prioritaire"]: boolean }>()
.orderBy("libelleFormation", "asc")
.orderBy("libelleNiveauDiplome", "asc")
.orderBy("libelleDispositif", "asc")
Expand All @@ -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,
}),
})),
};
};
66 changes: 34 additions & 32 deletions server/src/modules/demandes/usecases/getDemande/getDemande.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")},
sql<string>`CONCAT(${ebDataFormation.ref("dataFormation.libelleFormation")},
' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')',
' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
' (',${ebDataFormation.ref("dataFormation.cfd")},')')`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
"isFCIL"
),
])
Expand All @@ -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(
Expand All @@ -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<string>`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")},
sql<string>`CONCAT(${ebDataFormation.ref("dataFormation.libelleFormation")},
' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')',
' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
' (',${ebDataFormation.ref("dataFormation.cfd")},')')`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
"isFCIL"
),
])
Expand All @@ -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"),
Expand Down Expand Up @@ -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),
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>`CONCAT(${ebDataFormation.ref("formationView.libelleFormation")},
' (',${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},')',
' (',${ebDataFormation.ref("formationView.cfd")},')')`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("formationView.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
sql<string>`CONCAT(
${ebDataFormation.ref("formationView.libelleFormation")},
' (',
${ebDataFormation.ref("niveauDiplome.libelleNiveauDiplome")},
')',
' (',
${ebDataFormation.ref("dataFormation.cfd")},
')')
`.as("libelleFormation"),
sql<boolean>`${ebDataFormation("dataFormation.codeNiveauDiplome", "in", ["381", "481", "581"])}`.as(
"isFCIL"
),
])
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/utils/formatFormationSpecifique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TypeFormationSpecifiqueType } from "shared/enum/formationSpecifiqu
import { TypeFormationSpecifiqueEnum } from "shared/enum/formationSpecifiqueEnum";

export const formatFormationSpecifique = (
formation: Record<TypeFormationSpecifiqueType, string | boolean | undefined | null>
formation: Record<Partial<TypeFormationSpecifiqueType>, string | boolean | undefined | null>
) => ({
[TypeFormationSpecifiqueEnum["Action prioritaire"]]:
TypeFormationSpecifiqueEnum["Action prioritaire"] in formation
Expand Down

0 comments on commit 03d884f

Please sign in to comment.