Skip to content

Commit

Permalink
Merge pull request #31 from Black-Sirius69/master
Browse files Browse the repository at this point in the history
Fix: minor bugfixes
  • Loading branch information
Mr-Emerald-Wolf authored Sep 6, 2023
2 parents 78ddfb5 + 59e2bdf commit 0dd17e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
16 changes: 14 additions & 2 deletions api/controllers/questions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const ques = require("../models/ques");
const jwt = require("jsonwebtoken");
const TestCaseModel = require("../models/testCasesModel");

async function getQuestionByID(req, res) {
try {
Expand Down Expand Up @@ -83,11 +85,21 @@ async function getByRound(req, res) {
async function deleteQuestion(req,res){
try{
const deletedItem = await ques.findByIdAndDelete(req.params.id);
<<<<<<< HEAD
console.log(req.body.id)

const testCases = await TestCaseModel.find().where(`_id: ${req.params.id}`).exec();

TestCaseModel.deleteMany(testCases);

=======
>>>>>>> ef7378f59c6d585adc405c4be1bc8a1b2cf8ca77
if (!deletedItem) {
return res.status(404).json({ message: 'Item not found' });
}
return res.status(201).json({
message: "Successfully Deleted"
message: "Successfully Deleted",
testCases: testCases
})
}
catch (error){
Expand Down Expand Up @@ -148,4 +160,4 @@ module.exports = {
getQuestionByID,
updateQuestion,
deleteQuestion
};
};
16 changes: 11 additions & 5 deletions api/controllers/testCasesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,29 @@ const deleteTestCase = async (req, res) => {
return res.status(201).json({ message: "Succesfully deleted test case" });
} catch (error) {
return res.status(500).json({
message: error.message,
message: "Failed to delete test case"
});
}
};

const updateTestCase = async (req, res) => {
try {
const testCase = await TestCaseModel.findById(req.params.id);
const { expectedOutput, input, number, hidden, time, memory, explanation, question } = req.body;

if (!testCase) {
return res.status(500).json({message: "Test case does not exist"});
}

const { expectedOutput, input, number, hidden, time, memory, group, question } = req.body;
console.log(hidden, expectedOutput);

testCase.expectedOutput = expectedOutput ? expectedOutput : testCase.expectedOutput;
testCase.input = input ? input : testCase.input;
testCase.hidden = hidden ? hidden : testCase.hidden;
testCase.hidden = hidden === undefined ? hidden : testCase.hidden;
testCase.number = number ? number : testCase.number;
testCase.time = time ? time : testCase.time;
testCase.memory = memory ? memory : testCase.memory;
testCase.explanation = explanation ? explanation : testCase.explanation;
testCase.group = group ? group : testCase.group;

if (question) {
const oldQuestion = await QuestionModel.findById(testCase.question);
Expand All @@ -77,7 +83,7 @@ const updateTestCase = async (req, res) => {

return res.status(201).json({ testCase });
} catch (error) {
return res.status(500).json({ message: error.message });
return res.status(500).json({ message: "Failed to update test cases" });
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/routes/questionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ router.post("/getRound", getByRound);
router.put("/updateQuestion/:id", verifyAdminToken, updateQuestion);
router.delete("/deleteQuestion/:id",verifyAdminToken, deleteQuestion);

module.exports = router;
module.exports = router;

0 comments on commit 0dd17e1

Please sign in to comment.