Skip to content

Commit

Permalink
Merge pull request #19 from kushwahramkumar2003/ram
Browse files Browse the repository at this point in the history
Merge ram branch to features branch
  • Loading branch information
kushwahramkumar2003 authored Dec 9, 2023
2 parents 771af2d + ea7f6f6 commit 1161860
Show file tree
Hide file tree
Showing 61 changed files with 4,223 additions and 2,665 deletions.
2 changes: 1 addition & 1 deletion Server/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config = {
MONGODB_URL: process.env.MONGODB_URL || "mongodb://localhost:27017/quiz-app",
PORT: process.env.PORT || 3001,

JWT_SECRET: process.env.JWT_SECRET,
JWT_SECRET: process.env.JWT_SECRET || "thisisasecret",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "thisisasecret" is used as
key
.
The hard-coded value "thisisasecret" is used as
key
.
JWT_EXPIRE: process.env.JWT_EXPIRE || "1d",

SMTP_HOST: process.env.SMTP_HOST,
Expand Down
6 changes: 4 additions & 2 deletions Server/src/controllers/auth.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ exports.login = asyncHandler(async (req, res) => {

const { email, password } = req.body;

let user = await User.findOne({ email }, { email: 1, password: 1, name: 1 });
let user = await User.findOne(
{ email },

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
{ email: 1, password: 1, name: 1, role: 1 }
);
// console.log("user", user);
if (!user) {
return res.status(400).json({ msg: "Invalid Credentials" });
Expand All @@ -78,7 +81,6 @@ exports.login = asyncHandler(async (req, res) => {
res.status(200).json({
success: true,
message: "User logged in successfully",
data: user,
user,
});
});
Expand Down
10 changes: 4 additions & 6 deletions Server/src/controllers/quiz.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exports.addQuestionToQuiz = asyncHandler(async (req, res) => {
* @kushwahramkumar2003
**************************************************************************/
exports.getAllQuizzes = asyncHandler(async (req, res) => {
const quizzes = await Quiz.find({}, { questions: 0 }).populate().exec();
const quizzes = await Quiz.find({}).populate().exec();
res.json(quizzes);
});

Expand All @@ -114,7 +114,7 @@ exports.getAllQuizzes = asyncHandler(async (req, res) => {
*************************************************************************/
exports.getQuizById = asyncHandler(async (req, res) => {
const quiz = await Quiz.findById(req.params.id)
.populate("questions", "text options")
.populate("questions", "text options answer")
.exec();
if (quiz) {
res.json(quiz);
Expand Down Expand Up @@ -214,7 +214,7 @@ exports.deleteQuizById = asyncHandler(async (req, res) => {
await Question.deleteMany({ quiz: quizId });

// Delete all results corresponding to the quiz
await Result.deleteMany({ quiz: quizId });
await QuizResult.deleteMany({ quiz: quizId });

// Delete the quiz itself
// await Quiz.findByIdAndDelete(quizId);
Expand All @@ -238,16 +238,14 @@ exports.deleteQuestionById = asyncHandler(async (req, res) => {
return res.status(404).json({ success: false, message: "Quiz not found" });
}

const question = await Question.findById(questionId);
const question = await Question.findOneAndDelete(questionId);

if (!question) {
return res
.status(404)
.json({ success: false, message: "Question not found" });
}

await question.remove();

res
.status(200)
.json({ success: true, message: "Question deleted successfully" });
Expand Down
Loading

0 comments on commit 1161860

Please sign in to comment.