You are building the backend for a seminar evaluation service, using Express and MongoDB (Mongoose) only, with no frontend. Anyone can browse and submit seminar evaluations, and there is no login for this resource.
server/src/index.js,server/src/app.js,server/src/config/db.js— app bootstrap and DB connection. The/api/evaluationsrouter is already mounted inapp.js.server/src/models/User.js— a plain user schema (name,email,password). It's not tied to any login flow here; it exists soEvaluation.evaluatedByhas something to reference.server/src/controllers/userController.js+server/src/routes/users.js— full CRUD over users, already wired, as a worked example of what yourevaluationController.jsshould look like structurally (validation → DB call → response, one function per route).
cd server
npm install
# create server/.env (see "Database connection" below)
npm run dev
npm test
npm test uses the same MONGO_URI from your .env. Each test run creates
its own temporary database on that cluster and deletes it when it finishes,
so it never touches the data you use with npm run dev.
There is no .env provided. Create server/.env yourself (it's
git-ignored) with:
PORT=4000
MONGO_URI=mongodb://tasks:pass1234@ac-j3acrgb-shard-00-00.lueesfz.mongodb.net:27017,ac-j3acrgb-shard-00-01.lueesfz.mongodb.net:27017,ac-j3acrgb-shard-00-02.lueesfz.mongodb.net:27017/?ssl=true&replicaSet=atlas-6to6iy-shard-0&authSource=admin&appName=Cluster0
All of your work goes in three files: server/src/models/Evaluation.js,
server/src/controllers/evaluationController.js and
server/src/routes/evaluations.js.
| field | type | rules |
|---|---|---|
seminarCode |
String | required (e.g. "SM101") |
score |
Number | required, min: 1, max: 5 |
comment |
String | optional |
evaluatedBy |
ObjectId ref User |
optional |
Keep { timestamps: true } and add a compound unique index on
{ seminarCode: 1, evaluatedBy: 1 }.
Implement these three controller functions and wire them in
server/src/routes/evaluations.js:
| method | path | function | success response |
|---|---|---|---|
| POST | /api/evaluations |
createEvaluation |
201 { evaluation: <document> } |
| GET | /api/evaluations |
getAllEvaluations |
200 { evaluations: [...] } |
| GET | /api/evaluations/:id |
getEvaluation |
200 { evaluation: <document> } |
- For
GET /api/evaluations/:idon a valid id that does not exist, respond404with{ message: 'Evaluation not found' }. - Pass unexpected errors to
next(err), as the User controller does.
Implement getEvaluationSummary and wire it as
GET /api/evaluations/summary?seminarCode=SM101. It returns:
{ "seminarCode": "SM101", "averageScore": <number>, "evaluationCount": <integer> }
- Compute it with
Evaluation.aggregate():$matchonseminarCode, then$groupwith$avgofscoreand$sum: 1. Loading documents withfind()and averaging in JavaScript does not count. - If nothing matches, return the requested
seminarCodewithaverageScore: 0andevaluationCount: 0. - If the
seminarCodequery parameter is missing, respond400with{ message: 'seminarCode is required' }. /summarymust be reachable and must not be handled by/:id.
- Fork this repository and do all of your work in your fork.
- Commit and push to your fork.
- Open a pull request from your fork to
mainof this repository. - Fill in the pull request description using the provided template: the
submission line must be your identifier in the format
XX-XXXXX TXX.
You're expected to use AI tools while building this. You remain responsible for all of the code you submit.