Skip to content

Commit

Permalink
fix: changed submission request
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Emerald-Wolf committed Sep 9, 2023
1 parent 844f1eb commit a65ead9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
77 changes: 38 additions & 39 deletions api/controllers/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,47 +242,46 @@ class submission{
res.status(200).json(all);
}

async create_score(user){
const ele = await submission_db.aggregate([
{
$match : {regNo : user}
},
{
$group : {
_id : "$regNo",
total : {
$sum : "$score"
}
}
}
])
const score = ele[0].total;
return User.updateOne({regNo : user},{score : score})
.then(() => "Score = " + score)
.catch(() => "Error occured while saving scores");
}
async create_score(user) {
const ele = await submission_db.aggregate([
{
$match: { regNo: user },
},
{
$group: {
_id: "$regNo",
total: {
$sum: "$score",
},
},
},
]);
const score = ele[0].total;
return User.updateOne({ regNo: user }, { score: score })
.then(() => "Score = " + score)
.catch(() => "Error occured while saving scores");
}

async get_reg_no(req,res){
const authHeader = req.header('Authorization');
if (!authHeader) {
res.status(401).json({ message: 'Access denied. Token missing.' });
return 0;
}
const token = authHeader.replace('Bearer ', '');
try{
const decoded = jwt.verify(token, process.env.ACCESS_KEY_SECRET);
return decoded.regNo;
} catch{
res.status(401).json({ message: 'Invalid token.' });
return 0;
}
async get_reg_no(req, res) {
const authHeader = req.header("Authorization");
if (!authHeader) {
res.status(401).json({ message: "Access denied. Token missing." });
return 0;
}

async get_score(req,res){
const {regno} = req.params;
const record = await User.findOne({regNo : regno},"name regNo score");
res.status(200).json(record);
const token = authHeader.replace("Bearer ", "");
try {
const decoded = jwt.verify(token, process.env.ACCESS_KEY_SECRET);
return decoded.regNo;
} catch {
res.status(401).json({ message: "Invalid token." });
return 0;
}
}

async get_score(req, res) {
const { regno } = req.params;
const record = await User.findOne({ regNo: regno }, "name regNo score");
res.status(200).json(record);
}
}
module.exports = submission;
module.exports = submission;
5 changes: 2 additions & 3 deletions api/seeders/questions_seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mongoose

const testQuestions = [
{
name: "Smart Phone",
name: "Smart Phone6",
objective: `You are developing a smartphone app. You have a list of potential customers for your app. Each customer has a budget and will buy the app at your declared price if and only if the price is less than or equal to the customer's budget.
Expand Down Expand Up @@ -85,8 +85,7 @@ const addData = async () => {
let questions = JSON.parse(JSON.stringify(testQuestions));
questions.forEach((question) => (question.testCases = []));

await QuestionModel.deleteMany({});
await TestCaseModel.deleteMany({});

const insertedQuestions = await QuestionModel.insertMany(questions);

for (let i = 0; i < insertedQuestions.length; i++) {
Expand Down

0 comments on commit a65ead9

Please sign in to comment.