Skip to content

Commit

Permalink
[backend] Removed repetitive code
Browse files Browse the repository at this point in the history
  • Loading branch information
MananGandhi1810 committed Oct 31, 2024
1 parent 2297194 commit 3a993f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
40 changes: 9 additions & 31 deletions backend/router/editorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 3a993f0

Please sign in to comment.