Update controllers to use toOldJSON functions

This commit is contained in:
advplyr 2025-01-04 15:20:41 -06:00
parent 7fae25a726
commit 6d52f88a96
20 changed files with 277 additions and 202 deletions

View file

@ -282,7 +282,7 @@ class Collection extends Model {
const libraryItem = book.libraryItem
delete book.libraryItem
libraryItem.media = book
return this.sequelize.models.libraryItem.getOldLibraryItem(libraryItem).toJSONExpanded()
return libraryItem.toOldJSONExpanded()
})
return json

View file

@ -122,45 +122,6 @@ class LibraryItem extends Model {
})
}
/**
*
* @param {import('sequelize').WhereOptions} [where]
* @returns {Array<objects.LibraryItem>} old library items
*/
static async getAllOldLibraryItems(where = null) {
let libraryItems = await this.findAll({
where,
include: [
{
model: this.sequelize.models.book,
include: [
{
model: this.sequelize.models.author,
through: {
attributes: []
}
},
{
model: this.sequelize.models.series,
through: {
attributes: ['sequence']
}
}
]
},
{
model: this.sequelize.models.podcast,
include: [
{
model: this.sequelize.models.podcastEpisode
}
]
}
]
})
return libraryItems.map((ti) => this.getOldLibraryItem(ti))
}
/**
* Convert an expanded LibraryItem into an old library item
*
@ -448,6 +409,47 @@ class LibraryItem extends Model {
})
}
/**
*
* @param {import('sequelize').WhereOptions} where
* @returns {Promise<LibraryItemExpanded[]>}
*/
static async findAllExpandedWhere(where = null) {
return this.findAll({
where,
include: [
{
model: this.sequelize.models.book,
include: [
{
model: this.sequelize.models.author,
through: {
attributes: []
}
},
{
model: this.sequelize.models.series,
through: {
attributes: ['sequence']
}
}
]
},
{
model: this.sequelize.models.podcast,
include: {
model: this.sequelize.models.podcastEpisode
}
}
],
order: [
// Ensure author & series stay in the same order
[this.sequelize.models.book, this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'],
[this.sequelize.models.book, this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
]
})
}
/**
*
* @param {string} libraryItemId
@ -611,7 +613,7 @@ class LibraryItem extends Model {
return {
libraryItems: libraryItems.map((li) => {
const oldLibraryItem = this.getOldLibraryItem(li).toJSONMinified()
const oldLibraryItem = li.toOldJSONMinified()
if (li.collapsedSeries) {
oldLibraryItem.collapsedSeries = li.collapsedSeries
}

View file

@ -357,7 +357,7 @@ class Playlist extends Model {
libraryItem.media = pmi.mediaItem
return {
libraryItemId: libraryItem.id,
libraryItem: this.sequelize.models.libraryItem.getOldLibraryItem(libraryItem).toJSONExpanded()
libraryItem: libraryItem.toOldJSONExpanded()
}
}
@ -368,7 +368,7 @@ class Playlist extends Model {
episodeId: pmi.mediaItemId,
episode: pmi.mediaItem.toOldJSONExpanded(libraryItem.id),
libraryItemId: libraryItem.id,
libraryItem: this.sequelize.models.libraryItem.getOldLibraryItem(libraryItem).toJSONMinified()
libraryItem: libraryItem.toOldJSONMinified()
}
})