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(api): 3692 - fix acceptRI #4556

Open
wants to merge 5 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
2 changes: 1 addition & 1 deletion api/src/controllers/representants-legaux.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ router.post("/accept-ri", tokenParentValidMiddleware, async (req, res) => {
const young = await YoungModel.findById(id);
if (!young) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });

young.set({ acceptRI: REGLEMENT_INTERIEUR_VERSION });
young.set({ parent1ValidationDate: new Date() });
await young.save({ fromUser: { firstName: `Parent of young : ${id}` } });

res.status(200).send({ ok: true, data: serializeYoung(young, young) });
Expand Down
3 changes: 3 additions & 0 deletions api/src/controllers/young/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ router.put("/accept-ri", passport.authenticate("young", { session: false, failWi
const young = await YoungModel.findById(req.user._id);
if (!young) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });

young.set({ acceptRI: REGLEMENT_INTERIEUR_VERSION });
await young.save({ fromUser: req.user });

await sendTemplate(SENDINBLUE_TEMPLATES.parent.PARENT1_REVALIDATE_RI, {
emailTo: [{ name: `${young.parent1FirstName} ${young.parent1LastName}`, email: young.parent1Email! }],
params: {
Expand Down
20 changes: 9 additions & 11 deletions api/src/crons/parentRevalidateRI.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ exports.handler = async () => {
const cursor = YoungModel.find({
cohort: cohorts,
status: { $nin: [YOUNG_STATUS.ABANDONED, YOUNG_STATUS.WITHDRAWN, YOUNG_STATUS.REFUSED, YOUNG_STATUS.NOT_ELIGIBLE] },
parent1ValidationDate: { $lt: newRiDate },
}).cursor();

let countNotice = 0;

await cursor.eachAsync(async (young) => {
if (new Date(young.acceptRI) < newRiDate) {
countNotice++;
await sendTemplate(SENDINBLUE_TEMPLATES.parent.PARENT1_REVALIDATE_RI, {
emailTo: [{ name: `${young.parent1FirstName} ${young.parent1LastName}`, email: young.parent1Email }],
params: {
cta: `${config.APP_URL}/representants-legaux/ri-consentement?token=${young.parent1Inscription2023Token}`,
youngFirstName: young.firstName,
youngName: young.lastName,
},
});
}
await sendTemplate(SENDINBLUE_TEMPLATES.parent.PARENT1_REVALIDATE_RI, {
emailTo: [{ name: `${young.parent1FirstName} ${young.parent1LastName}`, email: young.parent1Email }],
params: {
cta: `${config.APP_URL}/representants-legaux/ri-consentement?token=${young.parent1Inscription2023Token}`,
youngFirstName: young.firstName,
youngName: young.lastName,
},
});
});

slack.success({ title: "1 week notice pending parent RI validation", text: `${countNotice} parents have been noticed!` });
Expand Down
Loading