JSDoc formatting updates

This commit is contained in:
advplyr 2024-05-07 17:39:10 -05:00
parent fd22a6f51d
commit 672672dd2a

View File

@ -4,43 +4,44 @@ const Database = require('../../Database')
module.exports = { module.exports = {
/** /**
* Get authors total count * Get authors total count
*
* @param {string} libraryId * @param {string} libraryId
* @returns {number} count * @returns {Promise<number>} count
*/ */
async getAuthorsTotalCount(libraryId) { async getAuthorsTotalCount(libraryId) {
const authorsCount = await Database.authorModel.count({ const authorsCount = await Database.authorModel.count({
where: { where: {
libraryId: libraryId libraryId: libraryId
} }
}); })
return authorsCount; return authorsCount
}, },
/** /**
* Get authors with count of num books * Get authors with count of num books
* @param {string} libraryId *
* @param {number} limit * @param {string} libraryId
* @returns {{id:string, name:string, count:number}} * @param {number} limit
* @returns {Promise<{id:string, name:string, count:number}>}
*/ */
async getAuthorsWithCount(libraryId, limit) { async getAuthorsWithCount(libraryId, limit) {
const authors = await Database.bookAuthorModel.findAll({ const authors = await Database.bookAuthorModel.findAll({
include: [{ include: [
model: Database.authorModel, {
as: 'author', // Use the correct alias as defined in your associations model: Database.authorModel,
attributes: ['name'], as: 'author', // Use the correct alias as defined in your associations
where: { attributes: ['name'],
libraryId: libraryId 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 group: ['authorId', 'author.id'], // Include 'author.id' to satisfy GROUP BY with JOIN
order: [[Sequelize.literal('count'), 'DESC']], order: [[Sequelize.literal('count'), 'DESC']],
limit: limit limit: limit
}) })
return authors.map(au => { return authors.map((au) => {
return { return {
id: au.authorId, id: au.authorId,
name: au.author.name, name: au.author.name,
@ -51,11 +52,12 @@ module.exports = {
/** /**
* Search authors * Search authors
* @param {string} libraryId *
* @param {string} query * @param {string} libraryId
* @param {string} query
* @param {number} limit * @param {number} limit
* @param {number} offset * @param {number} offset
* @returns {object[]} oldAuthor with numBooks * @returns {Promise<Object[]>} oldAuthor with numBooks
*/ */
async search(libraryId, query, limit, offset) { async search(libraryId, query, limit, offset) {
const authors = await Database.authorModel.findAll({ const authors = await Database.authorModel.findAll({
@ -66,9 +68,7 @@ module.exports = {
libraryId libraryId
}, },
attributes: { attributes: {
include: [ include: [[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']]
[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']
]
}, },
limit, limit,
offset offset