mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-03-04 23:19:42 +00:00
Fix multiple bugs
This commit is contained in:
parent
ef3f39191d
commit
f511e0046d
5 changed files with 198 additions and 188 deletions
|
|
@ -50,16 +50,18 @@ class Author extends Model {
|
|||
*
|
||||
* @param {string} authorName
|
||||
* @param {string} libraryId
|
||||
* @param {import('sequelize').Transaction} [transaction]
|
||||
* @returns {Promise<Author>}
|
||||
*/
|
||||
static async getByNameAndLibrary(authorName, libraryId) {
|
||||
static async getByNameAndLibrary(authorName, libraryId, transaction = null) {
|
||||
return this.findOne({
|
||||
where: [
|
||||
where(fn('lower', col('name')), authorName.toLowerCase()),
|
||||
{
|
||||
libraryId
|
||||
}
|
||||
]
|
||||
],
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -111,16 +113,20 @@ class Author extends Model {
|
|||
*
|
||||
* @param {string} name
|
||||
* @param {string} libraryId
|
||||
* @param {import('sequelize').Transaction} [transaction]
|
||||
* @returns {Promise<Author>}
|
||||
*/
|
||||
static async findOrCreateByNameAndLibrary(name, libraryId) {
|
||||
const author = await this.getByNameAndLibrary(name, libraryId)
|
||||
static async findOrCreateByNameAndLibrary(name, libraryId, transaction = null) {
|
||||
const author = await this.getByNameAndLibrary(name, libraryId, transaction)
|
||||
if (author) return author
|
||||
return this.create({
|
||||
name,
|
||||
lastFirst: this.getLastFirst(name),
|
||||
libraryId
|
||||
})
|
||||
return this.create(
|
||||
{
|
||||
name,
|
||||
lastFirst: this.getLastFirst(name),
|
||||
libraryId
|
||||
},
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,13 +27,15 @@ class BookAuthor extends Model {
|
|||
* Get number of books for author
|
||||
*
|
||||
* @param {string} authorId
|
||||
* @param {import('sequelize').Transaction} [transaction]
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static getCountForAuthor(authorId) {
|
||||
static getCountForAuthor(authorId, transaction = null) {
|
||||
return this.count({
|
||||
where: {
|
||||
authorId
|
||||
}
|
||||
},
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,16 +41,18 @@ class Series extends Model {
|
|||
*
|
||||
* @param {string} seriesName
|
||||
* @param {string} libraryId
|
||||
* @param {import('sequelize').Transaction} [transaction]
|
||||
* @returns {Promise<Series>}
|
||||
*/
|
||||
static async getByNameAndLibrary(seriesName, libraryId) {
|
||||
static async getByNameAndLibrary(seriesName, libraryId, transaction = null) {
|
||||
return this.findOne({
|
||||
where: [
|
||||
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
||||
{
|
||||
libraryId
|
||||
}
|
||||
]
|
||||
],
|
||||
transaction
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -70,16 +72,20 @@ class Series extends Model {
|
|||
*
|
||||
* @param {string} seriesName
|
||||
* @param {string} libraryId
|
||||
* @param {import('sequelize').Transaction} [transaction]
|
||||
* @returns {Promise<Series>}
|
||||
*/
|
||||
static async findOrCreateByNameAndLibrary(seriesName, libraryId) {
|
||||
const series = await this.getByNameAndLibrary(seriesName, libraryId)
|
||||
static async findOrCreateByNameAndLibrary(seriesName, libraryId, transaction = null) {
|
||||
const series = await this.getByNameAndLibrary(seriesName, libraryId, transaction)
|
||||
if (series) return series
|
||||
return this.create({
|
||||
name: seriesName,
|
||||
nameIgnorePrefix: getTitleIgnorePrefix(seriesName),
|
||||
libraryId
|
||||
})
|
||||
return this.create(
|
||||
{
|
||||
name: seriesName,
|
||||
nameIgnorePrefix: getTitleIgnorePrefix(seriesName),
|
||||
libraryId
|
||||
},
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue