Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Get q&A using ID #906

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what id it denotes? can you name it properly questionId or answerId


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('/:id', validation(getAnswerValidationSchema), getAnswers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above


// 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.get('/getallquestions', getAllQuestion);

// This route will give question by given id
router.get('/getQuestionById', getQuestionById);
router.get('/:getQuestionById', getQuestionById);
Fixed Show fixed Hide fixed

// This route will increase upvote by one.
router.patch('/upvote', upvoteQuestion);
Expand Down
Loading