generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:CS3219-AY2324S1/ay2324s1-course-a…
…ssessment-g53
- Loading branch information
Showing
27 changed files
with
2,738 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: question-backend CI | ||
|
||
on: | ||
push: | ||
branches: ['master'] | ||
pull_request: | ||
branches: ['master'] | ||
|
||
defaults: | ||
run: | ||
working-directory: backend/question-backend | ||
|
||
jobs: | ||
question-backend_test_and_coverage: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Backend | ||
uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20.x' | ||
- name: Install Dependencies | ||
run: npm install mocha chai sinon --save-dev | ||
npm install --save-dev c8 | ||
working-directory: backend/question-backend | ||
|
||
- name: Run Tests with Coverage | ||
run: npm run test-with-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { Schema, model } = require("mongoose") | ||
const roomSchema = new Schema({ | ||
_id: String, | ||
question: Object | ||
}) | ||
|
||
module.exports = model("roomSchema", roomSchema) |
33 changes: 33 additions & 0 deletions
33
backend/question-backend/controller/getQuestionsByComplexity.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Question from "../model/Question.js"; | ||
|
||
export async function getQuestionsByComplexity(req, res) { | ||
try { | ||
// Extract complexity from the request (e.g., from query parameters) | ||
const { complexity } = req.params; | ||
console.log(complexity, req.params) | ||
|
||
// If no complexity is provided, return an error response | ||
if (!complexity) { | ||
return res.status(400).send("Complexity parameter is required"); | ||
} | ||
|
||
// Find one question with the specified complexity | ||
const question = await Question.aggregate([ | ||
{ $match: { complexity: complexity } }, // Filter by the specified complexity | ||
{ $sample: { size: 1 } } // Get one random document | ||
]).exec(); | ||
|
||
// Since aggregate returns an array, extract the first element | ||
const randomQuestion = question[0]; | ||
|
||
// If no question is found, return a not found response | ||
if (!randomQuestion) { | ||
return res.status(404).send("No question found for the specified complexity"); | ||
} | ||
|
||
res.send(randomQuestion); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send("ERROR"); | ||
} | ||
} |
Oops, something went wrong.