mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-02 01:05:25 +02:00
Refactor Feed model to create new feed for collection
This commit is contained in:
parent
ca2327aba3
commit
d576625cb7
7 changed files with 171 additions and 93 deletions
|
@ -1,6 +1,7 @@
|
|||
const { DataTypes, Model, Sequelize } = require('sequelize')
|
||||
|
||||
const oldCollection = require('../objects/Collection')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class Collection extends Model {
|
||||
constructor(values, options) {
|
||||
|
@ -18,6 +19,11 @@ class Collection extends Model {
|
|||
this.updatedAt
|
||||
/** @type {Date} */
|
||||
this.createdAt
|
||||
|
||||
// Expanded properties
|
||||
|
||||
/** @type {import('./Book').BookExpandedWithLibraryItem[]} - only set when expanded */
|
||||
this.books
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,6 +225,34 @@ class Collection extends Model {
|
|||
Collection.belongsTo(library)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all books in collection expanded with library item
|
||||
*
|
||||
* @returns {Promise<import('./Book').BookExpandedWithLibraryItem[]>}
|
||||
*/
|
||||
getBooksExpandedWithLibraryItem() {
|
||||
return this.getBooks({
|
||||
include: [
|
||||
{
|
||||
model: this.sequelize.models.libraryItem
|
||||
},
|
||||
{
|
||||
model: this.sequelize.models.author,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: this.sequelize.models.series,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
}
|
||||
],
|
||||
order: [Sequelize.literal('`collectionBook.order` ASC')]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get old collection toJSONExpanded, items filtered for user permissions
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue