Skip to content

Commit

Permalink
fix(api): 3624 - Corriger le PUT de la réinscription (#4510)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobret committed Nov 5, 2024
1 parent 6c186c8 commit 01c0b0e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions api/src/controllers/young/reinscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ router.put("/", passport.authenticate("young", { session: false, failWithError:

if (!young) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });

const cohortObj = await CohortModel.findOne({ name: value.cohort });
if (!cohortObj) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });

// Check if the young has access to reinscription
if (!hasAccessToReinscription(young, cohortObj)) return res.status(403).send({ ok: false, code: ERRORS.OPERATION_UNAUTHORIZED });

// Validate request body
const { error, value } = Joi.object({
schooled: Joi.string().trim().required(),
Expand All @@ -53,6 +47,12 @@ router.put("/", passport.authenticate("young", { session: false, failWithError:
return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
}

const cohortObj = await CohortModel.findOne({ name: value.cohort });
if (!cohortObj) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });

// Check if the young has access to reinscription
if (!hasAccessToReinscription(young, cohortObj)) return res.status(403).send({ ok: false, code: ERRORS.OPERATION_UNAUTHORIZED });

// complete values
value.status = YOUNG_STATUS.REINSCRIPTION;
value.originalCohort = young.cohort;
Expand Down

0 comments on commit 01c0b0e

Please sign in to comment.