Skip to content

Commit

Permalink
Added limit variable to getAuthorsWithCount()
Browse files Browse the repository at this point in the history
- Clarified and updated the comments
- added parameter "limit" to getAuthorsWithCount()
- the limit is set to 10 when called from LibraryController.js
- as per Nichwall's comments
  • Loading branch information
CoffeeKnyte authored May 1, 2024
1 parent 7229cfc commit 5041f80
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/utils/queries/authorFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
/**
* Get authors total count
* @param {string} libraryId
* @returns {{id:string, name:string, count:number}}
* @returns {number} count
*/
async getAuthorsTotalCount(libraryId) {
const authorsCount = await Database.authorModel.count({
Expand All @@ -19,9 +19,10 @@ module.exports = {
/**
* Get authors with count of num books
* @param {string} libraryId
* @param {number} limit
* @returns {{id:string, name:string, count:number}}
*/
async getAuthorsWithCount(libraryId) {
async getAuthorsWithCount(libraryId, limit) {
const authors = await Database.bookAuthorModel.findAll({
include: [{
model: Database.authorModel,
Expand All @@ -37,7 +38,7 @@ module.exports = {
],
group: ['authorId', 'author.id'], // Include 'author.id' to satisfy GROUP BY with JOIN
order: [[Sequelize.literal('count'), 'DESC']],
limit: 10
limit: limit
})
return authors.map(au => {
return {
Expand Down

0 comments on commit 5041f80

Please sign in to comment.