Skip to content

Commit

Permalink
πŸ€ Backend Get q&A using ID (#906)
Browse files Browse the repository at this point in the history
* Backend fixed

* Update index.js

* Update index.js

* Update getAnswers.js

* Update index.js
  • Loading branch information
Hemu21 authored May 16, 2024
1 parent b0cc517 commit 330d647
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/app/routes/Q&A/answers/getAnswers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }])
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routes/Q&A/answers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routes/Q&A/question/getQuestionById.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routes/Q&A/question/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 330d647

Please sign in to comment.