mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-19 00:18:56 +01:00
JSDoc formatting updates
This commit is contained in:
parent
fd22a6f51d
commit
672672dd2a
@ -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,
|
||||
@ -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({
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user