Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): 204 - Attendre la fin du séjour pour ouvrir la possibilité de candidater aux MIGs #4707

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions api/src/controllers/mission.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,15 @@ router.get("/:id", passport.authenticate(["referent", "young"], { session: false
const application = await ApplicationModel.findOne({ missionId: checkedId, youngId: req.user._id });
const cohort = await CohortModel.findById(req.user.cohortId);
if (!cohort) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });
const data = {
...serializeMission(mission),
tutor: missionTutor,
application: application ? serializeApplication(application) : null,
...(await getAuthorizationToApply(mission, req.user, cohort)),
};
return res.status(200).send({
ok: true,
data: {
...serializeMission(mission),
tutor: missionTutor,
application: application ? serializeApplication(application) : null,
...(await getAuthorizationToApply(mission, req.user, cohort)),
},
data,
});
}
return res.status(200).send({ ok: true, data: { ...serializeMission(mission), tutor: missionTutor } });
Expand Down
13 changes: 6 additions & 7 deletions packages/lib/src/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { regionsListDROMS } from "./region-and-departments";
import { COHORT_STATUS, YOUNG_STATUS } from "./constants/constants";
import { COHORT_STATUS, YOUNG_STATUS, YOUNG_STATUS_PHASE1 } from "./constants/constants";
import { getZonedDate } from "./utils/date";
import { EtablissementDto } from "./dto";
import { format } from "date-fns";
Expand Down Expand Up @@ -140,12 +140,11 @@ function hasAccessToReinscription(young: YoungType) {
return young.cohort === "à venir";
}

//@todo : for browser apps better logic in app isYoungCanApplyToPhase2Missions (also takes into account timezone)
function canApplyToPhase2(young, cohort) {
if (young.statusPhase2OpenedAt && new Date(young.statusPhase2OpenedAt) < new Date()) return true;
const now = new Date();
const dateEnd = getCohortEndDate(cohort);
return ["DONE", "EXEMPTED"].includes(young.statusPhase1) && now >= dateEnd;
function canApplyToPhase2(young: YoungType, cohort: CohortType) {
const hasStartedPhase2 = young.statusPhase2OpenedAt && new Date() > new Date(young.statusPhase2OpenedAt);
const cohortHasStarted = new Date() < getCohortStartDate(cohort);
const cohortHasEnded = new Date() > getCohortEndDate(cohort);
return hasStartedPhase2 && !cohortHasStarted && cohortHasEnded;
}

export {
Expand Down
Loading