Commit e5c1b89a by Иван Кубота

is_top

parent f56cc843
......@@ -131,6 +131,15 @@ module.exports = {
var q = await asyncPool('SELECT * from `quiz_question` WHERE id=?', [args.body.quizQuestion]);
try{
log('answerQuiz', {question: {
id: args.body.quizQuestion,
correct: args.body.user_choice_correct
}});
}catch (e) {
}
if(args.body.currentQuestion === args.body.allQuestions - 1){
// calculations
if(q && q.length){
......@@ -148,9 +157,28 @@ module.exports = {
}
maxChain = Math.max(maxChain, curChain);
var is_top = false;
var attempt = (await asyncPool(`select a.*, p.question_count, p.top_count, p.prev_top_count from quiz_attempt as a left join quiz_position as p on p.id = a.quiz_position_id where a.id = ?;`, [q[0].attempt_id]))[0];
var userID = attempt.user_id;
var user = (await asyncPool(`select * from users where id=?;`, [userID]))[0];
var user_is_top = user.is_top;
is_top = (
(user_is_top && countCorrect >= attempt.prev_top_count) ||
(!user_is_top && countCorrect >= attempt.top_count)
);
await asyncPool(`update users set is_top=? where id=;`, [is_top, userID]);
return await asyncPool('UPDATE quiz_attempt SET ' +
'count_correct=?, max_chain=?, completed=?, completed_at=?' +
' WHERE id=?;', [countCorrect, maxChain, 1, new Date(), q[0].attempt_id])
'count_correct=?, max_chain=?, completed=?, completed_at=?, is_top=?' +
' WHERE id=?;', [countCorrect, maxChain, 1, new Date(), is_top,
q[0].attempt_id])
}else{
......@@ -158,10 +186,7 @@ module.exports = {
}
}
log('answerQuiz', {question: {
id: args.body.quizQuestion,
correct: args.body.user_choice_correct
}});
return {status: 'ok'};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment