diff --git a/backend/index.js b/backend/index.js index fda4393..0307732 100644 --- a/backend/index.js +++ b/backend/index.js @@ -24,7 +24,7 @@ app.use("/code", codeRouter); app.use("/problem-statement", problemStatementRouter); app.use("/leaderboard", leaderboardRouter); app.use("/user", userRouter); -app.use("/editorial", editorialsRouter); +app.use("/editorial/:problemStatementId", editorialsRouter); app.use(function (req, res, next) { res.status(404).json({ diff --git a/backend/router/editorial.js b/backend/router/editorial.js index 5a56a23..1714fc3 100644 --- a/backend/router/editorial.js +++ b/backend/router/editorial.js @@ -9,37 +9,15 @@ import { import { checkAuth } from "../middlewares/auth.js"; import { checkProblemStatement } from "../middlewares/problem-statement.js"; -const router = Router(); +const router = Router({ mergeParams: true }); -router.get( - "/:problemStatementId/", - checkAuth, - checkProblemStatement, - getEditorials, -); -router.get( - "/:problemStatementId/:editorialId", - checkAuth, - checkProblemStatement, - getEditorialById, -); -router.post( - "/:problemStatementId/new", - checkAuth, - checkProblemStatement, - newEditorial, -); -router.delete( - "/:problemStatementId/:editorialId/delete", - checkAuth, - checkProblemStatement, - deleteEditorial, -); -router.put( - "/:problemStatementId/:editorialId/update", - checkAuth, - checkProblemStatement, - updateEditorial, -); +router.use(checkAuth); +router.use(checkProblemStatement); + +router.get("/", getEditorials); +router.get("/:editorialId", getEditorialById); +router.post("/new", newEditorial); +router.delete("/:editorialId/delete", deleteEditorial); +router.put("/:editorialId/update", updateEditorial); export default router;