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

User and quiz info on a route #5

Open
meghprkh opened this issue Jul 1, 2016 · 10 comments
Open

User and quiz info on a route #5

meghprkh opened this issue Jul 1, 2016 · 10 comments

Comments

@meghprkh
Copy link
Contributor

meghprkh commented Jul 1, 2016

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
Copy link
Contributor Author

meghprkh commented Jul 1, 2016

Also if the scoring feature's score should be provided

@yash-iiith
Copy link
Contributor

yash-iiith commented Jul 10, 2016

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
Copy link
Contributor Author

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
Copy link
Contributor

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

@meghprkh
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

@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
Copy link
Contributor

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

@meghprkh
Copy link
Contributor Author

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

@meghprkh
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants