felicity-buzz-2k16 / quiz-portal-backend

The generic quiz portal's backend
ISC License
0 stars 7 forks source link

User and quiz info on a route #5

Open meghprkh opened 8 years ago

meghprkh commented 8 years ago

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 as lastQuestionAllowed and name.

meghprkh commented 8 years ago

Also if the scoring feature's score should be provided

yash-iiith commented 8 years ago
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?

meghprkh commented 8 years ago

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

yash-iiith commented 8 years ago

okay ,got it..i will try a better solution now..thanks

meghprkh commented 8 years ago

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

yash-iiith commented 8 years ago
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();
});
meghprkh commented 8 years ago

@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

anubhabsen commented 8 years ago

In the front end part, a new page /info and info button in nav?

meghprkh commented 8 years ago

@anubhabsen no you may use this to improve the questions page. For example you may stop displaying the next button when on lastQuestionAllowed

meghprkh commented 8 years ago

@yash-iiith If you need any help just comment =)