Skip to content

Commit

Permalink
additional functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sougatadafader committed Dec 6, 2018
1 parent 8769a7b commit 7b4ef9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 8 additions & 1 deletion dao/answer.dao.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ answerModel.findById(answerId).populate('student').populate('question').exec()
findAnswerByQidSid = (questionId,studentId) =>
answerModel.find({student: studentId}).find({question: questionId}).populate('student','username').populate('question','question').exec()

findAnswersByStudent = (studentId) =>
answerModel.find({student:studentId}).populate('student','username').populate('question','question').exec()

findAnswersByQuestion =(questionId) =>
answerModel.find({question : questionId}).populate('student','usename').populate('question','question').exec()

module.exports = {
createAnswer,
findAllAnswers,
findAnswerById,
findAnswerByQidSid
findAnswerByQidSid,
findAnswersByStudent,
findAnswersByQuestion
}
14 changes: 8 additions & 6 deletions services/answer.service.server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const answerDao = require('../dao/answer.dao.server')
module.exports = app => {
createAnswer = (req, res) =>
answerDao.createAnswer(req.body).then(data=>res.json(data))
{
let ansObj = req.body
ansObj['student'] = req.params.sid
ansObj['question'] = req.params.qid
answerDao.createAnswer(ansObj).then(data => res.json(data))
}
//res.json(AnswerDao.createAnswer(req.body))

findAllAnswers = (req, res) =>
{
/*console.log('Function called')
AnswerDao.findAllAnswers().then(function(Answers){
res.json(Answers)
})*/
answerDao.findAllAnswers().then(data=>res.json(data))
}

findAnswerById = (req, res) =>
answerDao.findAnswerById(req.params['answerId']).then(data=>res.json(data))

Expand All @@ -32,5 +34,5 @@ module.exports = app => {
app.delete('/api/answer/:answerId', deleteAnswer)
app.get('/api/answer/:answerId', findAnswerById)
app.get('/api/answer', findAllAnswers)
app.post('/api/answer', createAnswer)
app.post('/api/student/:sid/question/:qid/answer', createAnswer)
}

0 comments on commit 7b4ef9a

Please sign in to comment.