diff --git a/server/src/db/migrations/20240320100504-effectifs-computed-types.ts b/server/src/db/migrations/20240320100504-effectifs-computed-types.ts new file mode 100644 index 000000000..b480a6384 --- /dev/null +++ b/server/src/db/migrations/20240320100504-effectifs-computed-types.ts @@ -0,0 +1,5 @@ +import { addJob } from "job-processor"; + +export const up = async () => { + await addJob({ name: "tmp:effectifs:update_computed_statut", queued: true }); +}; diff --git a/server/src/jobs/hydrate/effectifs/hydrate-effectifs-computed-types.ts b/server/src/jobs/hydrate/effectifs/hydrate-effectifs-computed-types.ts index 44285ed59..c5c41e567 100644 --- a/server/src/jobs/hydrate/effectifs/hydrate-effectifs-computed-types.ts +++ b/server/src/jobs/hydrate/effectifs/hydrate-effectifs-computed-types.ts @@ -211,18 +211,20 @@ export function determineNewStatutFromHistorique( function genererHistoriqueStatutFromApprenant( historiqueStatut: IEffectifApprenant["historique_statut"], formationPeriode: number[] | null | undefined, - endDate: Date + evaluationEndDate: Date ): IEffectifComputedStatut["historique"] { if (!formationPeriode) { console.error("Formation period is undefined or null"); return []; } + const periodeEndDate = new Date(formationPeriode[1], 11, 31); const sortedStatut = historiqueStatut.sort( (a, b) => new Date(a.date_statut).getTime() - new Date(b.date_statut).getTime() ); const startDate = sortedStatut.length > 0 ? new Date(sortedStatut[0].date_statut) : new Date(formationPeriode[0], 0, 1); + const endDate = periodeEndDate < evaluationEndDate ? periodeEndDate : evaluationEndDate; let currentDate = new Date(startDate.getFullYear(), startDate.getMonth(), 1); const historique: IEffectifComputedStatut["historique"] = [];