From 3e40c6a850b0d0e084f8236dae31b26089e3aebd Mon Sep 17 00:00:00 2001 From: 3amrobaia Date: Thu, 1 Oct 2026 16:03:05 +0300 Subject: [PATCH] post --- .../src/controllers/evaluationController.js | 46 +++++++------------ server/src/models/Evaluation.js | 31 +++++++++++-- server/src/routes/evaluations.js | 12 ++++- 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/server/src/controllers/evaluationController.js b/server/src/controllers/evaluationController.js index 3d43598..9d71e47 100644 --- a/server/src/controllers/evaluationController.js +++ b/server/src/controllers/evaluationController.js @@ -1,33 +1,21 @@ -import { Evaluation } from '../models/Evaluation.js'; +import { Router } from 'express'; -// GET /api/evaluations -// TODO: implement per README.md section 2. -export async function getAllEvaluations(req, res, next) { - try { - // TODO - } catch (err) { next(err); } -} +import { + getAllEvaluations, + getEvaluation, + createEvaluation, + getEvaluationSummary +} from '../controllers/evaluationController.js'; -// GET /api/evaluations/:id -// TODO: implement per README.md section 2. -export async function getEvaluation(req, res, next) { - try { - // TODO - } catch (err) { next(err); } -} +const router = Router(); -// POST /api/evaluations -// TODO: implement per README.md section 2. -export async function createEvaluation(req, res, next) { - try { - // TODO - } catch (err) { next(err); } -} +router.get('/', getAllEvaluations); -// GET /api/evaluations/summary?seminarCode=SM101 -// TODO: implement per README.md section 3. -export async function getEvaluationSummary(req, res, next) { - try { - // TODO - } catch (err) { next(err); } -} +router.post('/', createEvaluation); + +// IMPORTANT: summary must come before /:id +router.get('/summary', getEvaluationSummary); + +router.get('/:id', getEvaluation); + +export default router; \ No newline at end of file diff --git a/server/src/models/Evaluation.js b/server/src/models/Evaluation.js index b7a7d5a..40a6aef 100644 --- a/server/src/models/Evaluation.js +++ b/server/src/models/Evaluation.js @@ -1,14 +1,35 @@ import mongoose from 'mongoose'; -// TODO: define the Evaluation schema per README.md section 1. - const evaluationSchema = new mongoose.Schema( { - // TODO + sessionCode: { + type: String, + required: true + }, + + score: { + type: Number, + required: true, + min: 1, + max: 5 + }, + + comment: { + type: String + }, + + evaluatedBy: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + } }, { timestamps: true } ); -// TODO: add the compound uniqueness constraint described in README.md section 1. +// One user can evaluate a specific session only once +evaluationSchema.index( + { sessionCode: 1, evaluatedBy: 1 }, + { unique: true } +); -export const Evaluation = mongoose.model('Evaluation', evaluationSchema); +export const Evaluation = mongoose.model('Evaluation', evaluationSchema); \ No newline at end of file diff --git a/server/src/routes/evaluations.js b/server/src/routes/evaluations.js index 00ec53e..9d71e47 100644 --- a/server/src/routes/evaluations.js +++ b/server/src/routes/evaluations.js @@ -1,4 +1,5 @@ import { Router } from 'express'; + import { getAllEvaluations, getEvaluation, @@ -8,6 +9,13 @@ import { const router = Router(); -// TODO: wire up the three routes in README.md section 2 and the summary route in section 3. +router.get('/', getAllEvaluations); + +router.post('/', createEvaluation); + +// IMPORTANT: summary must come before /:id +router.get('/summary', getEvaluationSummary); + +router.get('/:id', getEvaluation); -export default router; +export default router; \ No newline at end of file