2023-07-05 01:14:44 +02:00
|
|
|
/**
|
|
|
|
* TODO: Unused for testing
|
|
|
|
*/
|
|
|
|
const { Sequelize } = require('sequelize')
|
|
|
|
const Database = require('../Database')
|
|
|
|
|
|
|
|
const getLibraryItemMinified = (libraryItemId) => {
|
2023-08-20 20:34:03 +02:00
|
|
|
return Database.libraryItemModel.findByPk(libraryItemId, {
|
2023-07-05 01:14:44 +02:00
|
|
|
include: [
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.bookModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
attributes: [
|
|
|
|
'id', 'title', 'subtitle', 'publishedYear', 'publishedDate', 'publisher', 'description', 'isbn', 'asin', 'language', 'explicit', 'narrators', 'coverPath', 'genres', 'tags'
|
|
|
|
],
|
|
|
|
include: [
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.authorModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
attributes: ['id', 'name'],
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.seriesModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
attributes: ['id', 'name'],
|
|
|
|
through: {
|
|
|
|
attributes: ['sequence']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.podcastModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
attributes: [
|
|
|
|
'id', 'title', 'author', 'releaseDate', 'feedURL', 'imageURL', 'description', 'itunesPageURL', 'itunesId', 'itunesArtistId', 'language', 'podcastType', 'explicit', 'autoDownloadEpisodes', 'genres', 'tags',
|
|
|
|
[Sequelize.literal('(SELECT COUNT(*) FROM "podcastEpisodes" WHERE "podcastEpisodes"."podcastId" = podcast.id)'), 'numPodcastEpisodes']
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const getLibraryItemExpanded = (libraryItemId) => {
|
2023-08-20 20:34:03 +02:00
|
|
|
return Database.libraryItemModel.findByPk(libraryItemId, {
|
2023-07-05 01:14:44 +02:00
|
|
|
include: [
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.bookModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
include: [
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.authorModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.seriesModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
through: {
|
|
|
|
attributes: ['sequence']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.podcastModel,
|
2023-07-05 01:14:44 +02:00
|
|
|
include: [
|
|
|
|
{
|
2023-08-20 20:34:03 +02:00
|
|
|
model: Database.podcastEpisodeModel
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'libraryFolder',
|
|
|
|
'library'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getLibraryItemMinified,
|
|
|
|
getLibraryItemExpanded
|
|
|
|
}
|