New data model change of Book media type to include array of Audiobook and Ebook objects

This commit is contained in:
advplyr 2022-03-16 19:15:25 -05:00
parent 0af6ad63c1
commit 4fe60465e5
13 changed files with 677 additions and 334 deletions

View file

@ -0,0 +1,70 @@
const EBookFile = require('../files/EBookFile')
const { areEquivalent, copyValue } = require('../../utils/index')
class EBook {
constructor(ebook) {
this.id = null
this.index = null
this.name = null
this.ebookFile = null
this.addedAt = null
this.updatedAt = null
if (ebook) {
this.construct(ebook)
}
}
construct(ebook) {
this.id = ebook.id
this.index = ebook.index
this.name = ebook.name
this.ebookFile = new EBookFile(ebook.ebookFile)
this.addedAt = ebook.addedAt
this.updatedAt = ebook.updatedAt
}
toJSON() {
return {
id: this.id,
index: this.index,
name: this.name,
ebookFile: this.ebookFile.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt
}
}
toJSONMinified() {
return {
id: this.id,
index: this.index,
name: this.name,
ebookFormat: this.ebookFile.ebookFormat,
addedAt: this.addedAt,
updatedAt: this.updatedAt,
size: this.size
}
}
toJSONMinified() {
return {
id: this.id,
index: this.index,
name: this.name,
ebookFile: this.ebookFile.toJSON(),
addedAt: this.addedAt,
updatedAt: this.updatedAt,
size: this.size
}
}
get size() {
return this.ebookFile.metadata.size
}
findFileWithInode(inode) {
return this.ebookFile.ino === inode
}
}
module.exports = EBook