Start of new data model

This commit is contained in:
advplyr 2022-03-08 19:31:44 -06:00
parent 2b7f53b0a7
commit 65793f7109
18 changed files with 672 additions and 8 deletions

View file

@ -0,0 +1,45 @@
class Author {
constructor(author) {
this.id = null
this.asin = null
this.name = null
this.imagePath = null
this.imageFullPath = null
this.addedAt = null
this.updatedAt = null
if (author) {
this.construct(author)
}
}
construct(author) {
this.id = author.id
this.asin = author.asin
this.name = author.name
this.imagePath = author.imagePath
this.imageFullPath = author.imageFullPath
this.addedAt = author.addedAt
this.updatedAt = author.updatedAt
}
toJSON() {
return {
id: this.id,
asin: this.asin,
name: this.name,
imagePath: this.imagePath,
imageFullPath: this.imageFullPath,
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
toJSONMinimal() {
return {
id: this.id,
name: this.name
}
}
}
module.exports = Author

View file

@ -0,0 +1,41 @@
const BookMetadata = require('../metadata/BookMetadata')
const AudioFile = require('../files/AudioFile')
const EBookFile = require('../files/EBookFile')
const AudioTrack = require('../AudioTrack')
class Book {
constructor(book) {
this.metadata = null
this.tags = []
this.audioFiles = []
this.ebookFiles = []
this.audioTracks = []
this.chapters = []
if (books) {
this.construct(book)
}
}
construct(book) {
this.metadata = new BookMetadata(book.metadata)
this.tags = [...book.tags]
this.audioFiles = book.audioFiles.map(f => new AudioFile(f))
this.ebookFiles = book.ebookFiles.map(f => new EBookFile(f))
this.audioTracks = book.audioTracks.map(a => new AudioTrack(a))
this.chapters = book.chapters.map(c => ({ ...c }))
}
toJSON() {
return {
metadata: this.metadata.toJSON(),
tags: [...this.tags],
audioFiles: this.audioFiles.map(f => f.toJSON()),
ebookFiles: this.ebookFiles.map(f => f.toJSON()),
audioTracks: this.audioTracks.map(a => a.toJSON()),
chapters: this.chapters.map(c => ({ ...c }))
}
}
}
module.exports = Book

View file

@ -0,0 +1,43 @@
const PodcastEpisode = require('./PodcastEpisode')
const PodcastMetadata = require('../metadata/PodcastMetadata')
class Podcast {
constructor(podcast) {
this.id = null
this.metadata = null
this.cover = null
this.coverFullPath = null
this.episodes = []
this.createdAt = null
this.lastUpdate = null
if (podcast) {
this.construct(podcast)
}
}
construct(podcast) {
this.id = podcast.id
this.metadata = new PodcastMetadata(podcast.metadata)
this.cover = podcast.cover
this.coverFullPath = podcast.coverFullPath
this.episodes = podcast.episodes.map((e) => new PodcastEpisode(e))
this.createdAt = podcast.createdAt
this.lastUpdate = podcast.lastUpdate
}
toJSON() {
return {
id: this.id,
metadata: this.metadata.toJSON(),
cover: this.cover,
coverFullPath: this.coverFullPath,
episodes: this.episodes.map(e => e.toJSON()),
createdAt: this.createdAt,
lastUpdate: this.lastUpdate
}
}
}
module.exports = Podcast

View file

@ -0,0 +1,38 @@
const AudioFile = require('../files/AudioFile')
class PodcastEpisode {
constructor(episode) {
this.id = null
this.podcastId = null
this.episodeNumber = null
this.audioFile = null
this.addedAt = null
this.updatedAt = null
if (episode) {
this.construct(episode)
}
}
construct(episode) {
this.id = episode.id
this.podcastId = episode.podcastId
this.episodeNumber = episode.episodeNumber
this.audioFile = new AudioFile(episode.audioFile)
this.addedAt = episode.addedAt
this.updatedAt = episode.updatedAt
}
toJSON() {
return {
id: this.id,
podcastId: this.podcastId,
episodeNumber: this.episodeNumber,
audioFile: this.audioFile.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
}
module.exports = PodcastEpisode

View file

@ -0,0 +1,40 @@
class Series {
constructor(series) {
this.id = null
this.name = null
this.sequence = null
this.addedAt = null
this.updatedAt = null
if (series) {
this.construct(series)
}
}
construct(series) {
this.id = series.id
this.name = series.name
this.sequence = series.sequence
this.addedAt = series.addedAt
this.updatedAt = series.updatedAt
}
toJSON() {
return {
id: this.id,
name: this.name,
sequence: this.sequence,
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
toJSONMinimal() {
return {
id: this.id,
name: this.name,
sequence: this.sequence
}
}
}
module.exports = Series