From 330d647ed6fdf62cf3967fd637616d976a6f88b7 Mon Sep 17 00:00:00 2001 From: Hemanth kumar Date: Thu, 16 May 2024 23:01:35 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=80=20Backend=20Get=20q&A=20using=20ID?= =?UTF-8?q?=20=20(#906)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Backend fixed * Update index.js * Update index.js * Update getAnswers.js * Update index.js --- 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..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.body.question_id; + const qId = req.params.questionId; 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..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('/', validation(getAnswerValidationSchema), getAnswers); +router.get('/:questionId', 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);