mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-03-05 23:49:41 +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 }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue