Skip to content

Commit

Permalink
get logged in user questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka-1996 committed Jul 3, 2022
1 parent a8032d9 commit 854ce1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ const connectDB = async () => {
}
}

module.exports = connectDB
module.exports = connectDB


11 changes: 10 additions & 1 deletion controller/questionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ const getQuestionsById = asyncHandler(async (req, res) => {
}
})

// get logged in user questions

const getQuestionByUser = asyncHandler(async (req, res) => {
const questions = await Question.find({user: req.user._id})
res.json(questions)
})

// create a question

const createQuestion = asyncHandler(async (req, res) => {


const {grade, subject, topic, description, image, replies} = req.body
console.log(req.body)
console.log(req.user)

if(!grade || !subject || !description) {
res.status(400)
Expand Down Expand Up @@ -124,4 +133,4 @@ const searchQuestion = asyncHandler(async (req, res) => {
res.send(questions)
})

module.exports = {getQuestions, createQuestion, getQuestionsById, updateQuestion, deleteQuestion, searchQuestion}
module.exports = {getQuestions, createQuestion, getQuestionsById, updateQuestion, deleteQuestion, searchQuestion, getQuestionByUser}
3 changes: 2 additions & 1 deletion routes/questions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const router = require('express').Router()
const {getQuestions, getQuestionsById, createQuestion, updateQuestion, deleteQuestion, searchQuestion} = require('../controller/questionController')
const {getQuestions, getQuestionsById, createQuestion, updateQuestion, deleteQuestion, searchQuestion, getQuestionByUser} = require('../controller/questionController')

const {protect} = require('../middleware/authMiddleware')
const {grantAccess} = require('../permission/permission')

router.route('/').get(getQuestions)
router.route('/get-question-by-user').get(protect, getQuestionByUser)
router.route('/getquestions').get(protect, searchQuestion)
router.route('/create').post(protect, createQuestion)
router.route('/:id').get(getQuestionsById).put(protect, updateQuestion).delete(protect, deleteQuestion)
Expand Down

0 comments on commit 854ce1d

Please sign in to comment.