fix: add question in group check + extra create question errors service

This commit is contained in:
Gabriellvl 2025-04-19 10:58:49 +02:00
parent 78b65f148e
commit 566bb5a5fb
4 changed files with 47 additions and 6 deletions

View file

@ -1,7 +1,11 @@
import express from 'express';
import { createAnswerHandler, deleteAnswerHandler, getAnswerHandler, getAllAnswersHandler, updateAnswerHandler } from '../controllers/answers.js';
import {adminOnly, authenticatedOnly, teachersOnly} from "../middleware/auth/checks/auth-checks";
import {onlyAllowAuthor, onlyAllowAuthorRequestAnswer} from "../middleware/auth/checks/question-checks";
import {
onlyAllowAuthor,
onlyAllowAuthorRequestAnswer,
onlyAllowIfHasAccessToQuestion
} from "../middleware/auth/checks/question-checks";
const router = express.Router({ mergeParams: true });
@ -10,7 +14,7 @@ router.get('/', adminOnly, getAllAnswersHandler);
router.post('/', teachersOnly, onlyAllowAuthor, createAnswerHandler);
router.get('/:seqAnswer', authenticatedOnly, getAnswerHandler);
router.get('/:seqAnswer', onlyAllowIfHasAccessToQuestion, getAnswerHandler);
router.delete('/:seqAnswer', teachersOnly, onlyAllowAuthorRequestAnswer, deleteAnswerHandler);

View file

@ -3,7 +3,11 @@ import { createQuestionHandler, deleteQuestionHandler, getAllQuestionsHandler, g
import answerRoutes from './answers.js';
import {adminOnly, authenticatedOnly, studentsOnly} from "../middleware/auth/checks/auth-checks";
import {updateAnswerHandler} from "../controllers/answers";
import {onlyAllowAuthor, onlyAllowAuthorRequest} from "../middleware/auth/checks/question-checks";
import {
onlyAllowAuthor,
onlyAllowAuthorRequest,
onlyAllowIfHasAccessToQuestion
} from "../middleware/auth/checks/question-checks";
const router = express.Router({ mergeParams: true });
@ -15,7 +19,7 @@ router.get('/', adminOnly, getAllQuestionsHandler);
router.post('/', studentsOnly, onlyAllowAuthor, createQuestionHandler);
// Information about a question with id
router.get('/:seq', authenticatedOnly, getQuestionHandler); // TODO every body in group + teachers?
router.get('/:seq', onlyAllowIfHasAccessToQuestion, getQuestionHandler);
router.delete('/:seq', studentsOnly, onlyAllowAuthorRequest, deleteQuestionHandler);