-
Notifications
You must be signed in to change notification settings - Fork 28
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
total-questions added to the attributes #15
base: master
Are you sure you want to change the base?
Conversation
@abhishek97 |
This would not work if i don't include all questions along with quiz. Ideally this should at controller level |
@abhishek97 sure ! const {rows, count} = this.findAll(...arguments)
rows = rows.map( _ => _.get({plain: true}))
rows.map(async row => {
const res = await QuizQuestions.find({
attributes: [Sequelize.fn('count', Sequelize.col('id')), 'questions'],
where: {
quizId: row.id
}
})
row['total-questions'] = res.questions
}) |
Can be done for
and then map total to the quizzes object |
@abhishek97 Thanks and done! 😄 🚀 |
@@ -7,7 +7,7 @@ const { adminOnly } = require('../../../passport/middlewares') | |||
|
|||
const controller = new BaseController(DB.quizzes) | |||
|
|||
routes.use(passport.authenticate('bearer', {session: false}), adminOnly) | |||
// routes.use(passport.authenticate('bearer', {session: false}), adminOnly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't mean to be like this
group: ['quizzes.id'] | ||
}) | ||
quizQuestionCounts = R.groupBy(obj => obj.id)(quizQuestionCounts) | ||
rows = rows.map( _ => _.get({plain: true})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these those map calls can be combined into one.
Fixes #13