Skip to content

Commit

Permalink
fix(api): 3659 - Correction bug sur etablissement vide lors d'un chan…
Browse files Browse the repository at this point in the history
…gement séjour d'un jeune
  • Loading branch information
Eric013 committed Nov 18, 2024
1 parent 6231cb0 commit 3662360
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions api/src/referent/referentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ router.put("/young/:id/change-cohort", passport.authenticate("referent", { sessi
cohesionStayMedicalFileReceived: undefined,
cohortId: cohortModel?._id,
});

if (payload.source === YOUNG_SOURCE.CLE) {
const correctionRequestsFiltered = young?.correctionRequests?.filter((correction) => correction.field !== "CniFile") || [];
young.set({
Expand Down Expand Up @@ -932,39 +933,41 @@ router.put("/young/:id/change-cohort", passport.authenticate("referent", { sessi
statusPhase1: YOUNG_STATUS_PHASE1.AFFECTED,
});
}
} else {
if (payload.source === YOUNG_SOURCE.VOLONTAIRE) {
if (young.source !== YOUNG_SOURCE.VOLONTAIRE) {
young.set({
statusPhase1: YOUNG_STATUS_PHASE1.WAITING_AFFECTATION,
cniFiles: [],
"files.cniFiles": [],
latestCNIFileExpirationDate: undefined,
latestCNIFileCategory: undefined,
});
}
}
} else if (payload.source === YOUNG_SOURCE.VOLONTAIRE) {
const step2023 = young.hasStartedReinscription ? "reinscriptionStep2023" : "inscriptionStep2023";
const step2023Value =
young.status === YOUNG_STATUS.NOT_AUTORISED ? "WAITING_CONSENT" : young.hasStartedReinscription ? young.reinscriptionStep2023 : young.inscriptionStep2023;
const school = await SchoolRAMSESModel.findOne({ uai: previousEtablissement?.uai });

// Only for CLE to HTS changes
if (young.source !== YOUNG_SOURCE.VOLONTAIRE) {
const school = await SchoolRAMSESModel.findOne({ uai: previousEtablissement?.uai });
young.set({
statusPhase1: YOUNG_STATUS_PHASE1.WAITING_AFFECTATION,
cniFiles: [],
"files.cniFiles": [],
latestCNIFileExpirationDate: undefined,
latestCNIFileCategory: undefined,
source: YOUNG_SOURCE.VOLONTAIRE,
etablissementId: undefined,
classeId: undefined,
schoolId: school?._id ?? undefined,
schoolName: school?.fullName ?? undefined,
schoolType: school?.type ?? undefined,
schoolAddress: school?.adresse ?? undefined,
schoolZip: school?.postcode ?? undefined,
schoolCity: school?.city ?? undefined,
schoolDepartment: school?.department ?? undefined,
schoolRegion: school?.region ?? undefined,
schoolCountry: school?.country ?? undefined,
});
}
// Only for HTS to HTS changes
young.set({
// Init if young was previously CLE
source: YOUNG_SOURCE.VOLONTAIRE,
status: youngStatus,
[step2023]: step2023Value,
etablissementId: undefined,
classeId: undefined,
schoolId: school?._id ?? undefined,
schoolName: school?.fullName ?? undefined,
schoolType: school?.type ?? undefined,
schoolAddress: school?.adresse ?? undefined,
schoolZip: school?.postcode ?? undefined,
schoolCity: school?.city ?? undefined,
schoolDepartment: school?.department ?? undefined,
schoolRegion: school?.region ?? undefined,
schoolCountry: school?.country ?? undefined,
});
} else {
return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
}

const date = new Date();
Expand Down

0 comments on commit 3662360

Please sign in to comment.