Add:Remove option for authors & show authors with 0 books on authors page #2124

This commit is contained in:
advplyr 2023-09-24 17:06:32 -05:00
parent 0367d9ec2a
commit 10011d3886
19 changed files with 79 additions and 5 deletions

View file

@ -167,6 +167,30 @@ class AuthorController {
}
}
/**
* DELETE: /api/authors/:id
* Remove author from all books and delete
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
async delete(req, res) {
Logger.info(`[AuthorController] Removing author "${req.author.name}"`)
await Database.authorModel.removeById(req.author.id)
if (req.author.imagePath) {
await CacheManager.purgeImageCache(req.author.id) // Purge cache
}
SocketAuthority.emitter('author_removed', req.author.toJSON())
// Update filter data
Database.removeAuthorFromFilterData(req.author.libraryId, req.author.id)
res.sendStatus(200)
}
async match(req, res) {
let authorData = null
const region = req.body.region || 'us'

View file

@ -620,7 +620,7 @@ class LibraryController {
model: Database.bookModel,
attributes: ['id', 'tags', 'explicit'],
where: bookWhere,
required: true,
required: false,
through: {
attributes: []
}

View file

@ -47,10 +47,14 @@ class BookAuthor extends Model {
book.belongsToMany(author, { through: BookAuthor })
author.belongsToMany(book, { through: BookAuthor })
book.hasMany(BookAuthor)
book.hasMany(BookAuthor, {
onDelete: 'CASCADE'
})
BookAuthor.belongsTo(book)
author.hasMany(BookAuthor)
author.hasMany(BookAuthor, {
onDelete: 'CASCADE'
})
BookAuthor.belongsTo(author)
}
}

View file

@ -199,6 +199,7 @@ class ApiRouter {
//
this.router.get('/authors/:id', AuthorController.middleware.bind(this), AuthorController.findOne.bind(this))
this.router.patch('/authors/:id', AuthorController.middleware.bind(this), AuthorController.update.bind(this))
this.router.delete('/authors/:id', AuthorController.middleware.bind(this), AuthorController.delete.bind(this))
this.router.post('/authors/:id/match', AuthorController.middleware.bind(this), AuthorController.match.bind(this))
this.router.get('/authors/:id/image', AuthorController.middleware.bind(this), AuthorController.getImage.bind(this))