From b39701d417ca23fb4726ee3d40589f9f56549f4e Mon Sep 17 00:00:00 2001 From: Hemu21 Date: Thu, 16 May 2024 21:19:12 +0530 Subject: [PATCH 1/5] Backend fixed --- backend/app/routes/Q&A/answers/getAnswers.js | 2 +- backend/app/routes/Q&A/answers/index.js | 2 +- backend/app/routes/Q&A/question/getQuestionById.js | 2 +- backend/app/routes/Q&A/question/index.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/routes/Q&A/answers/getAnswers.js b/backend/app/routes/Q&A/answers/getAnswers.js index e58a4793..14ddff07 100644 --- a/backend/app/routes/Q&A/answers/getAnswers.js +++ b/backend/app/routes/Q&A/answers/getAnswers.js @@ -5,7 +5,7 @@ const { ErrorHandler } = require('../../../../helpers/error'); const constants = require('../../../../constants'); module.exports = async (req, res, next) => { - const qId = req.body.question_id; + const qId = req.params.id; const [err, answers] = await to( Answer.aggregate([{ $match: { question_id: mongoose.Types.ObjectId(qId) } }, { $sort: { upvotes: -1 } }]) diff --git a/backend/app/routes/Q&A/answers/index.js b/backend/app/routes/Q&A/answers/index.js index 06c724b1..a794e6e5 100644 --- a/backend/app/routes/Q&A/answers/index.js +++ b/backend/app/routes/Q&A/answers/index.js @@ -12,7 +12,7 @@ const updateAnswerStatus = require('./updateAnswerStatus'); router.post('/', validation(answerValidationSchema), postAnswer); // GET API FOR ANSWERS -router.get('/', validation(getAnswerValidationSchema), getAnswers); +router.get('/:id', validation(getAnswerValidationSchema), getAnswers); // INCREASE UPVOTE FOR ANSWERS router.patch('/upvote', upvoteAnswer); diff --git a/backend/app/routes/Q&A/question/getQuestionById.js b/backend/app/routes/Q&A/question/getQuestionById.js index 825ee212..9c1b797e 100644 --- a/backend/app/routes/Q&A/question/getQuestionById.js +++ b/backend/app/routes/Q&A/question/getQuestionById.js @@ -2,7 +2,7 @@ const question = require('../../../models/question'); module.exports = async (req, res) => { try { - const { questionId } = req.body; // Getting question id from body + const { questionId } = req.params; // Getting question id from body const result = await question.findOne({ _id: questionId }); // Find the question corresponding to the given id return res.json(result); } catch (error) { diff --git a/backend/app/routes/Q&A/question/index.js b/backend/app/routes/Q&A/question/index.js index b2421e3a..9271bdc9 100644 --- a/backend/app/routes/Q&A/question/index.js +++ b/backend/app/routes/Q&A/question/index.js @@ -14,7 +14,7 @@ router.post('/', validation(QuestionValidationSchema), postQuestion); router.get('/getallquestions', getAllQuestion); // This route will give question by given id -router.get('/getQuestionById', getQuestionById); +router.get('/getQuestionById/:questionId', getQuestionById); // This route will increase upvote by one. router.patch('/upvote', upvoteQuestion); From 3c0f9e633b12952e015c1977c7dbafc233dc2fd8 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Thu, 16 May 2024 21:51:08 +0530 Subject: [PATCH 2/5] Update index.js --- backend/app/routes/Q&A/question/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/routes/Q&A/question/index.js b/backend/app/routes/Q&A/question/index.js index 9271bdc9..c6541cad 100644 --- a/backend/app/routes/Q&A/question/index.js +++ b/backend/app/routes/Q&A/question/index.js @@ -14,7 +14,7 @@ router.post('/', validation(QuestionValidationSchema), postQuestion); router.get('/getallquestions', getAllQuestion); // This route will give question by given id -router.get('/getQuestionById/:questionId', getQuestionById); +router.get('/:getQuestionById', getQuestionById); // This route will increase upvote by one. router.patch('/upvote', upvoteQuestion); From c352cd48982ef0c3b8d7b92dac8e0b46cc113066 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Thu, 16 May 2024 21:53:20 +0530 Subject: [PATCH 3/5] Update index.js --- backend/app/routes/Q&A/question/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/routes/Q&A/question/index.js b/backend/app/routes/Q&A/question/index.js index c6541cad..9271bdc9 100644 --- a/backend/app/routes/Q&A/question/index.js +++ b/backend/app/routes/Q&A/question/index.js @@ -14,7 +14,7 @@ router.post('/', validation(QuestionValidationSchema), postQuestion); router.get('/getallquestions', getAllQuestion); // This route will give question by given id -router.get('/:getQuestionById', getQuestionById); +router.get('/getQuestionById/:questionId', getQuestionById); // This route will increase upvote by one. router.patch('/upvote', upvoteQuestion); From 43841408c6bb4146edeaf0cea8ead6014b972637 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Thu, 16 May 2024 22:54:46 +0530 Subject: [PATCH 4/5] Update getAnswers.js --- backend/app/routes/Q&A/answers/getAnswers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/routes/Q&A/answers/getAnswers.js b/backend/app/routes/Q&A/answers/getAnswers.js index 14ddff07..68000a31 100644 --- a/backend/app/routes/Q&A/answers/getAnswers.js +++ b/backend/app/routes/Q&A/answers/getAnswers.js @@ -5,7 +5,7 @@ const { ErrorHandler } = require('../../../../helpers/error'); const constants = require('../../../../constants'); module.exports = async (req, res, next) => { - const qId = req.params.id; + const qId = req.params.questionId; const [err, answers] = await to( Answer.aggregate([{ $match: { question_id: mongoose.Types.ObjectId(qId) } }, { $sort: { upvotes: -1 } }]) From 28e2e522e588b62447009692c088d7f752ac6419 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Thu, 16 May 2024 22:55:22 +0530 Subject: [PATCH 5/5] Update index.js --- backend/app/routes/Q&A/answers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/routes/Q&A/answers/index.js b/backend/app/routes/Q&A/answers/index.js index a794e6e5..104cece4 100644 --- a/backend/app/routes/Q&A/answers/index.js +++ b/backend/app/routes/Q&A/answers/index.js @@ -12,7 +12,7 @@ const updateAnswerStatus = require('./updateAnswerStatus'); router.post('/', validation(answerValidationSchema), postAnswer); // GET API FOR ANSWERS -router.get('/:id', validation(getAnswerValidationSchema), getAnswers); +router.get('/:questionId', validation(getAnswerValidationSchema), getAnswers); // INCREASE UPVOTE FOR ANSWERS router.patch('/upvote', upvoteAnswer);