Skip to content

Commit

Permalink
Merge pull request #57 from Killerrekt/master
Browse files Browse the repository at this point in the history
Added an admin route for a round of a user
  • Loading branch information
aditansh authored Sep 23, 2023
2 parents fb7c15a + 425ea3e commit 6b56cb5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
55 changes: 55 additions & 0 deletions api/controllers/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class submission {
if (failed.length != tests.length && data_sent_back.error[0]) {
data_sent_back.error[0] = false;
data_sent_back.error[1] = true;
data_sent_back.error[2] = true;
data_sent_back.error[3] = true;
}

//In case of complilation error the following code will run
Expand All @@ -294,6 +296,8 @@ class submission {
return;
}

if(data_sent_back.error[2]) data_sent_back.error[3] = true;

//Calculate the score of the given code
Object.keys(grp).forEach((element) => {
let check = true;
Expand All @@ -308,6 +312,7 @@ class submission {
}
});


//comparing the score with the existing score and picking the best one
data_sent_back.Score =
!check || score >= check.score ? score : check.score;
Expand Down Expand Up @@ -494,5 +499,55 @@ class submission {
});
res.status(200).json(items);
}

async get_round(req, res) {
const { regno,round } = req.body;
console.log(regno,round);
//console.log(regno);
const question = await questiondb.find(
{round : round},"_id name points"
);
let ids = [];
question.forEach((ele) => ids.push(ele._id.toString()));
console.log(ids);
const record = await submission_db.find(
{ regNo: regno , question_id : {"$in" : ids}},
"code score question_id lastResults language_id",
);
//console.log(record);
if (record.length == 0) {
res.status(400).json({
Error: "Invalid regNo",
});
return;
}
let msg = [];
let i = 0;
let number = 0;
record.forEach((element) => {
const curr = question[ids.indexOf(element.question_id.toString())];
const name = curr.name;
const points = curr.points;
const results = element.lastResults;
const compilation_error = results[0];
const runtime_error = results[1];
const time_limit_exceeded = results[2];
const output_no_match = results[3];
const data = {
question_id: element.question_id,
name : name,
points : points,
code: element.code,
score: element.score,
compilation_error: compilation_error,
runtime_error: runtime_error,
time_limit_exceeded: time_limit_exceeded,
output_did_not_match: output_no_match,
language_id: element.language_id,
};
msg.push(data);
});
res.status(200).json(msg);
}
}
module.exports = submission;
5 changes: 5 additions & 0 deletions api/routes/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
verifyAccessToken,
verifyQuestion,
} = require("../middleware/jwtMiddleware.js");
const { verify } = require("jsonwebtoken");

const submit = new submission();

Expand Down Expand Up @@ -33,5 +34,9 @@ router.get("/round_lb/:round", verifyAdminToken, (req, res)=> {
submit.round_lb(req,res);
});

router.get("/codes_by_round", verifyAdminToken, (req,res) =>{
submit.get_round(req,res);
})


module.exports = router;

0 comments on commit 6b56cb5

Please sign in to comment.