Skip to content

Commit

Permalink
refacto: delete edit-moderation route
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccadumazert committed Jan 10, 2025
1 parent cb11a03 commit bd07fba
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 135 deletions.
43 changes: 2 additions & 41 deletions src/controllers/user/edit-moderation.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import type { NextFunction, Request, Response } from "express";
import HttpErrors from "http-errors";
import { z } from "zod";
import { NotFoundError } from "../../config/errors";
import { cancelModeration } from "../../managers/moderation";
import { getUserFromAuthenticatedSession } from "../../managers/session/authenticated";

import { z } from "zod";
import {
cancelModeration,
getOrganizationFromModeration,
} from "../../managers/moderation";
import { csrfToken } from "../../middlewares/csrf-protection";
import { idSchema } from "../../services/custom-zod-schemas";

export const getEditModerationController = async (
req: Request,
res: Response,
next: NextFunction,
) => {
try {
const user = getUserFromAuthenticatedSession(req);

const schema = z.object({
moderation_id: idSchema(),
});
let { moderation_id } = await schema.parseAsync(req.query);

const { cached_libelle } = await getOrganizationFromModeration({
user,
moderation_id,
});

return res.render("user/edit-moderation", {
pageTitle: "Modifier une demande de rattachement en cours",
email: user.email,
csrfToken: csrfToken(req),
organization_label: cached_libelle,
moderation_id,
});
} catch (error) {
if (error instanceof NotFoundError) {
return next(new HttpErrors.NotFound());
}
next(error);
}
};

export const postCancelModerationAndRedirectControllerFactory =
(redirectUrl: string) =>
async (req: Request, res: Response, next: NextFunction) => {
Expand Down
12 changes: 1 addition & 11 deletions src/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import {
import { postSignInWithAuthenticatorAppController } from "../controllers/totp";
import { get2faSignInController } from "../controllers/user/2fa-sign-in";
import { postDeleteUserController } from "../controllers/user/delete";
import {
getEditModerationController,
postCancelModerationAndRedirectControllerFactory,
} from "../controllers/user/edit-moderation";
import { postCancelModerationAndRedirectControllerFactory } from "../controllers/user/edit-moderation";
import { issueSessionOrRedirectController } from "../controllers/user/issue-session-or-redirect";
import {
getMagicLinkSentController,
Expand Down Expand Up @@ -327,13 +324,6 @@ export const userRouter = () => {
getUnableToAutoJoinOrganizationController,
);

userRouter.get(
"/edit-moderation",
checkUserHasPersonalInformationsMiddleware,
csrfProtectionMiddleware,
getEditModerationController,
);

userRouter.post(
"/cancel-moderation-and-redirect-to-sign-in/:moderation_id",
rateLimiterMiddleware,
Expand Down
83 changes: 0 additions & 83 deletions src/views/user/edit-moderation.ejs

This file was deleted.

0 comments on commit bd07fba

Please sign in to comment.