Skip to content

Commit

Permalink
Merge pull request #30 from Oik17/master
Browse files Browse the repository at this point in the history
Changed schema of questions
  • Loading branch information
Mr-Emerald-Wolf authored Sep 5, 2023
2 parents 9954c08 + f90fa9d commit ef7378f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
10 changes: 2 additions & 8 deletions api/controllers/questions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ques = require("../models/ques");
const jwt = require("jsonwebtoken");

async function getQuestionByID(req, res) {
try {
Expand Down Expand Up @@ -84,7 +83,6 @@ async function getByRound(req, res) {
async function deleteQuestion(req,res){
try{
const deletedItem = await ques.findByIdAndDelete(req.params.id);
console.log(req.body.id)
if (!deletedItem) {
return res.status(404).json({ message: 'Item not found' });
}
Expand Down Expand Up @@ -120,25 +118,21 @@ async function updateQuestion(req,res){
};

async function createQuestion(req, res) {
//admin only
try {
const Ques = await ques.create({
name: req.body.name,
id: req.body.id,
inputFormat: req.body.inputFormat,
outputFormat: req.body.outputFormat,
constraints: req.body.constraints,
round: req.body.round,
sampleTestInput: req.body.sampleTestInput,
sampleTestOutput: req.body.sampleTestOutput,
timeLimit: req.body.timeLimit,
sourceLimit: req.body.sourceLimit,
round: req.body.round,
explanation: req.body.explanation,
objective: req.body.objective,
testCases: [],
});
await Ques.save();

console.log(Ques);
return res.status(201).json(Ques);
} catch (error) {
return res.status(500).json({
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/testCasesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const createTestCase = async (req, res) => {
hidden: req.body.hidden,
time: req.body.time,
memory: req.body.memory,
group: req.body.group,
question: req.body.question,

});

const question = await QuestionModel.findById(req.body.question);
Expand Down
4 changes: 3 additions & 1 deletion api/models/ques.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const quesSchema = new mongoose.Schema({
inputFormat: [{ type: String }],
outputFormat: [{ type: String }],
constraints: [{ type: String, required: true }],
round: { type: Number, required: true },
sampleTestInput: [{ type: String, required: true }],
sampleTestOutput: [{ type: String, required: true }],
round: { type: Number, required: true },
explanation: [{type: String}],
points: {type: Number},
testCases: [{ type: mongoose.Schema.Types.ObjectId, ref: "Testcase" }],
});

Expand Down
2 changes: 1 addition & 1 deletion api/models/testCasesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const TestCaseSchema = new mongoose.Schema({
hidden: { type: Boolean, default: false },
time: { type: Number, default: 0 },
memory: { type: Number, default: 0 },
explanation: { type: String },
group: { type: String },
question: { type: mongoose.Schema.Types.ObjectId, ref: "Question" },
});

Expand Down

0 comments on commit ef7378f

Please sign in to comment.