Open meghprkh opened 8 years ago
Also if the scoring feature's score should be provided
router.get('/info', middleware.isAuthenticated, (req, res)=>{
const { lastQuestionAllowed } = req.user;
const { name } = req.user;
var qno=1;
var f=0;
while(qno>=1)
{
model.Question.findOne({
where : {qno}}).then(question=>{
if(question) qno++;
else f=1;
})
if (f==1)
break;
}
res.send(lastQuestionAllowed,name,qno-1);
});
if i add this route in /src/question.js , will it solve the issue?
It may work, but you are not using sql properly see http://docs.sequelizejs.com/en/latest/docs/models-usage/#max-get-the-greatest-value-of-a-specific-attribute-within-a-specific-table . Also this doesnot take advantage of nodes capability to pause requests and continue oon to handling other requests while data is being fetched
okay ,got it..i will try a better solution now..thanks
Also see this for formatting https://guides.github.com/features/mastering-markdown/ . Its easy and useful. Another thing is dont use 1/0
flags you can use boolean flags true/false
router.get('/info', middleware.isAuthenticated, (req, res)=>{
const { lastQuestionAllowed } = req.user;
const { name } = req.user;
var noOfQuestions=models.Question.max('qno').then(function(max){})
res.write(noOfQuestions);
res.write(name);
res.write(lastQuestionAllowed);
res.end();
});
@yash-iiith nah this wont work... try to understand callbacks and promises . Maybe see this http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/ Dunno a better reference
In the front end part, a new page /info and info button in nav?
@anubhabsen no you may use this to improve the questions page. For example you may stop displaying the next button when on lastQuestionAllowed
@yash-iiith If you need any help just comment =)
Currently the frontend doesnot have a way to know how many questions are there in the quiz. It would be good to have a route lets say
/info
which gives the quiz info (the number of questions in the quiz) and if the user is logged in provide the user info such aslastQuestionAllowed
andname
.