Skip to content

Commit

Permalink
feat: mise a jour des indicateurs en contrat avant date inscription (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrmr authored Apr 24, 2024
1 parent 140e1c7 commit 7681cd2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"jsonwebtoken": "8.5.1",
"lil-http-terminator": "^1.2.3",
"lodash-es": "4.17.21",
"lodash.clonedeep": "^4.5.0",
"lodash.groupby": "4.6.0",
"lodash.indexby": "3.1.1",
"lodash.omit": "4.5.0",
Expand Down
27 changes: 21 additions & 6 deletions server/src/common/actions/effectifs.statut.actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { captureException } from "@sentry/node";
import Boom from "boom";
import { cloneDeep } from "lodash-es";
import { MongoServerError, UpdateFilter } from "mongodb";
import { STATUT_APPRENANT, StatutApprenant } from "shared/constants";
import { IEffectif, IEffectifApprenant, IEffectifComputedStatut } from "shared/models/data/effectifs.model";
Expand Down Expand Up @@ -152,9 +153,6 @@ export function determineStatutsByContrats(
const dateFin = effectif.formation.date_fin ? new Date(effectif.formation.date_fin) : currentDate;
const effectiveDateFin = dateFin < currentDate ? dateFin : currentDate;

if (dateEntree) statuts.push({ valeur: STATUT_APPRENANT.INSCRIT, date: dateEntree });

let latestRuptureDate;
let contracts =
effectif.contrats
?.map((contract) => ({
Expand All @@ -163,6 +161,15 @@ export function determineStatutsByContrats(
}))
.sort((a, b) => a.dateDebut.getTime() - b.dateDebut.getTime()) || [];

const earliestContract = contracts[0]?.dateDebut;

if (dateEntree && earliestContract && earliestContract < dateEntree) {
statuts.push({ valeur: STATUT_APPRENANT.INSCRIT, date: earliestContract });
} else if (dateEntree) {
statuts.push({ valeur: STATUT_APPRENANT.INSCRIT, date: dateEntree });
}

let latestRuptureDate;
contracts.forEach((contract, index) => {
const { dateDebut, dateRupture } = contract;

Expand Down Expand Up @@ -205,19 +212,27 @@ function determineNewStatutFromHistorique(
throw new Error("La période de formation est nulle ou indéfinie");
}

const sortedHistoriqueStatut = historiqueStatut.sort(
const clonedHistoriqueStatut = cloneDeep(historiqueStatut);

const sortedHistoriqueStatut = clonedHistoriqueStatut.sort(
(a, b) => new Date(a.date_statut).getTime() - new Date(b.date_statut).getTime()
);

const [startYear, endYear] = formationPeriode;
let inscriptionDate =
startYear !== endYear ? new Date(`${startYear}-08-01T00:00:00Z`) : new Date(`${startYear}-01-01T00:00:00Z`);

if (sortedHistoriqueStatut[0].valeur_statut === 0) {
inscriptionDate = new Date(sortedHistoriqueStatut[0].date_statut);
if (sortedHistoriqueStatut[0].valeur_statut === 2) {
inscriptionDate = sortedHistoriqueStatut[0].date_statut;
sortedHistoriqueStatut.shift();
}

let earliestStatutDate = new Date(sortedHistoriqueStatut[0].date_statut);

if (earliestStatutDate < inscriptionDate) {
inscriptionDate = earliestStatutDate;
}

const parcours: { valeur: StatutApprenant; date: Date }[] = [
{ valeur: STATUT_APPRENANT.INSCRIT, date: inscriptionDate },
];
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12647,6 +12647,13 @@ __metadata:
languageName: node
linkType: hard

"lodash.clonedeep@npm:^4.5.0":
version: 4.5.0
resolution: "lodash.clonedeep@npm:4.5.0"
checksum: 92c46f094b064e876a23c97f57f81fbffd5d760bf2d8a1c61d85db6d1e488c66b0384c943abee4f6af7debf5ad4e4282e74ff83177c9e63d8ff081a4837c3489
languageName: node
linkType: hard

"lodash.debounce@npm:4.0.8, lodash.debounce@npm:^4.0.8":
version: 4.0.8
resolution: "lodash.debounce@npm:4.0.8"
Expand Down Expand Up @@ -17751,6 +17758,7 @@ __metadata:
jsonwebtoken: 8.5.1
lil-http-terminator: ^1.2.3
lodash-es: 4.17.21
lodash.clonedeep: ^4.5.0
lodash.groupby: 4.6.0
lodash.indexby: 3.1.1
lodash.omit: 4.5.0
Expand Down

0 comments on commit 7681cd2

Please sign in to comment.