Skip to content

Commit

Permalink
Merge pull request #20 from kushwahramkumar2003/features
Browse files Browse the repository at this point in the history
Merge features to main branch
  • Loading branch information
kushwahramkumar2003 authored Dec 9, 2023
2 parents 08f3d86 + 1161860 commit 795381f
Show file tree
Hide file tree
Showing 61 changed files with 4,226 additions and 2,668 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",
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 },
{ 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
16 changes: 7 additions & 9 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 Expand Up @@ -347,7 +345,7 @@ exports.getQuizResults = asyncHandler(async (req, res) => {
return res.status(404).json({ message: "Quiz not found" });
}

const results = await Result.find({ quiz: quiz._id }).populate(
const results = await QuizResult.find({ quiz: quiz._id }).populate(
"user",
"name email"
);
Expand Down Expand Up @@ -452,7 +450,7 @@ exports.submitQuizOnTimeUp = asyncHandler(async (req, res) => {
exports.getQuizResultsForUser = asyncHandler(async (req, res) => {
try {
const { id, userId } = req.params;
const quizResults = await QuizResults.findOne({
const quizResults = await QuizResult.findOne({
quiz: id,
user: userId,
}).populate("quiz", "title");
Expand All @@ -474,7 +472,7 @@ exports.getQuizResultsForUser = asyncHandler(async (req, res) => {
exports.getAllResultsForQuiz = asyncHandler(async (req, res) => {
try {
const { id } = req.params;
const quizResults = await QuizResults.find({ quiz: id }).populate(
const quizResults = await QuizResult.find({ quiz: id }).populate(
"user",
"name email"
);
Expand Down
Loading

0 comments on commit 795381f

Please sign in to comment.