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

chore(api): 2716 - add from user mission from controller #4534

Merged
merged 2 commits into from
Nov 15, 2024
Merged
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/cle/classe/classeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ router.post(

if (!etablissement.schoolYears.includes(ClasseSchoolYear.YEAR_2024_2025)) {
etablissement.set({ schoolYears: [...etablissement.schoolYears, ClasseSchoolYear.YEAR_2024_2025] });
await etablissement.save();
await etablissement.save({ fromUser: req.user });
}

if (!payload.referent?._id) {
Expand Down
6 changes: 3 additions & 3 deletions api/src/cle/referent/referentSignupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ router.put("/request-confirmation-email", async (req: UserRequest, res: Response

const token2FA = await crypto.randomInt(1000000);
referent.set({ emailWaitingValidation: value.email, token2FA, attempts2FA: 0, token2FAExpires: Date.now() + 1000 * 60 * 10 });
await referent.save();
await referent.save({ fromUser: req.user });

let cta = `${config.ADMIN_URL}/creer-mon-compte/code?token=${value.invitationToken}&code=${token2FA}`;
if (referent.lastLoginAt) {
Expand Down Expand Up @@ -124,7 +124,7 @@ router.post("/confirm-email", async (req: UserRequest, res: Response) => {
token2FAExpires: null,
attempts2FA: 0,
});
await referent.save();
await referent.save({ fromUser: req.user });

return res.status(200).send({ ok: true, data: serializeReferent(referent) });
} catch (error) {
Expand Down Expand Up @@ -214,7 +214,7 @@ router.post("/", async (req: UserRequest, res: Response) => {
phone: value.phone,
phoneZone: value.phoneZone,
});
await referent.save();
await referent.save({ fromUser: req.user });

return res.status(200).send({ ok: true, data: serializeReferent(referent) });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ router.put("/:id", passport.authenticate("referent", { session: false, failWithE
}

schema.set(value);
await schema.save();
await schema.save({ fromUser: req.user });

const IsSchemaDownloadIsTrue = await CohortModel.find({ name: schema.cohort, dateEnd: { $gt: new Date().getTime() } }, [
"name",
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ router.put("/:id", passport.authenticate("referent", { session: false, failWithE
const data = await ProgramModel.findById(checkedId);
if (!data) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND });
data.set(obj);
await data.save();
await data.save({ fromUser: req.user });
return res.status(200).send({ ok: true, data });
} catch (error) {
capture(error);
Expand Down
4 changes: 2 additions & 2 deletions api/src/controllers/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ router.get("/token", async (req, res) => {
if (user) {
if (passwordChangedAt?.getTime() === user.passwordChangedAt?.getTime() && lastLogoutAt?.getTime() === user.lastLogoutAt?.getTime()) {
user.set({ lastActivityAt: Date.now() });
await user.save();
await user.save({ fromUser: req.user });
return res.status(200).send({ ok: true, user: { ...serializeYoung(user, user), allowedRole: "young" } });
}
}
Expand All @@ -73,7 +73,7 @@ router.get("/token", async (req, res) => {
if (user) {
if (passwordChangedAt?.getTime() === user.passwordChangedAt?.getTime() && lastLogoutAt?.getTime() === user.lastLogoutAt?.getTime()) {
user.set({ lastActivityAt: Date.now() });
await user.save();
await user.save({ fromUser: req.user });
return res.status(200).send({ ok: true, user: { ...serializeReferent(user, user), allowedRole: allowedRole(user) } });
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/jeveuxaider.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ router.get("/signin", async (req, res) => {
// si l'utilisateur existe, on le connecte, et on le redirige vers la plateforme admin SNU
if (user) {
user.set({ lastLoginAt: Date.now() });
await user.save();
await user.save({ fromUser: user });

const token = jwt.sign({ __v: JWT_SIGNIN_VERSION, _id: user.id, lastLogoutAt: user.lastLogoutAt, passwordChangedAt: user.passwordChangedAt }, config.JWT_SECRET, {
expiresIn: JWT_SIGNIN_MAX_AGE_SEC,
Expand Down
6 changes: 3 additions & 3 deletions api/src/young/edition/youngEditionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ router.put("/:id/identite", passport.authenticate("referent", { session: false,

const updatePromises = applications.map((application) => {
application.set({ youngCity: value.city, youngDepartment: value.department });
return application.save();
return application.save({ fromUser: req.user });
});

await Promise.all(updatePromises);
Expand Down Expand Up @@ -623,7 +623,7 @@ router.put("/:id/parent-image-rights-reset", passport.authenticate("referent", {
if (parentId === 2) {
young.set({ parent2AllowImageRightsReset: "true" });
}
await young.save();
await young.save({ fromUser: req.user });

// --- send notification
await sendTemplate(SENDINBLUE_TEMPLATES.parent[`PARENT${parentId}_RESEND_IMAGERIGHT`], {
Expand Down Expand Up @@ -667,7 +667,7 @@ router.put("/:id/parent-allow-snu-reset", passport.authenticate("referent", { se
young.set({ parentAllowSNU: undefined, parent1AllowSNU: undefined, status: YOUNG_STATUS.IN_PROGRESS, parent1ValidationDate: undefined });
// FIXME: parent2Id: legacy
// if (young.parent2Id) young.set({ parent2AllowSnu: undefined, parent2ValidationDate: undefined });
await young.save();
await young.save({ fromUser: req.user });

// --- send notification
// parent 1
Expand Down
Loading