Skip to content

Commit

Permalink
JSDoc formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed May 7, 2024
1 parent fd22a6f commit 672672d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions server/utils/queries/authorFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@ const Database = require('../../Database')
module.exports = {
/**
* Get authors total count
*
* @param {string} libraryId
* @returns {number} count
* @returns {Promise<number>} count
*/
async getAuthorsTotalCount(libraryId) {
const authorsCount = await Database.authorModel.count({
where: {
libraryId: libraryId
}
});
return authorsCount;
})
return authorsCount
},

/**
* Get authors with count of num books
* @param {string} libraryId
* @param {number} limit
* @returns {{id:string, name:string, count:number}}
*
* @param {string} libraryId
* @param {number} limit
* @returns {Promise<{id:string, name:string, count:number}>}
*/
async getAuthorsWithCount(libraryId, limit) {
const authors = await Database.bookAuthorModel.findAll({
include: [{
model: Database.authorModel,
as: 'author', // Use the correct alias as defined in your associations
attributes: ['name'],
where: {
libraryId: libraryId
include: [
{
model: Database.authorModel,
as: 'author', // Use the correct alias as defined in your associations
attributes: ['name'],
where: {
libraryId: libraryId
}
}
}],
attributes: [
'authorId',
[Sequelize.fn('COUNT', Sequelize.col('authorId')), 'count']
],
attributes: ['authorId', [Sequelize.fn('COUNT', Sequelize.col('authorId')), 'count']],
group: ['authorId', 'author.id'], // Include 'author.id' to satisfy GROUP BY with JOIN
order: [[Sequelize.literal('count'), 'DESC']],
limit: limit
})
return authors.map(au => {
return authors.map((au) => {
return {
id: au.authorId,
name: au.author.name,
Expand All @@ -51,11 +52,12 @@ module.exports = {

/**
* Search authors
* @param {string} libraryId
* @param {string} query
*
* @param {string} libraryId
* @param {string} query
* @param {number} limit
* @param {number} offset
* @returns {object[]} oldAuthor with numBooks
* @returns {Promise<Object[]>} oldAuthor with numBooks
*/
async search(libraryId, query, limit, offset) {
const authors = await Database.authorModel.findAll({
Expand All @@ -66,9 +68,7 @@ module.exports = {
libraryId
},
attributes: {
include: [
[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']
]
include: [[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']]
},
limit,
offset
Expand Down

0 comments on commit 672672d

Please sign in to comment.