mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-13 17:38:40 +01:00
Update Author model to define types
This commit is contained in:
parent
6d6e8613cf
commit
7afda1295b
@ -102,7 +102,7 @@ class Database {
|
|||||||
require('./models/MediaProgress')(this.sequelize)
|
require('./models/MediaProgress')(this.sequelize)
|
||||||
require('./models/Series')(this.sequelize)
|
require('./models/Series')(this.sequelize)
|
||||||
require('./models/BookSeries')(this.sequelize)
|
require('./models/BookSeries')(this.sequelize)
|
||||||
require('./models/Author')(this.sequelize)
|
require('./models/Author').init(this.sequelize)
|
||||||
require('./models/BookAuthor')(this.sequelize)
|
require('./models/BookAuthor')(this.sequelize)
|
||||||
require('./models/Collection')(this.sequelize)
|
require('./models/Collection')(this.sequelize)
|
||||||
require('./models/CollectionBook')(this.sequelize)
|
require('./models/CollectionBook')(this.sequelize)
|
||||||
|
@ -2,8 +2,30 @@ const { DataTypes, Model } = require('sequelize')
|
|||||||
|
|
||||||
const oldAuthor = require('../objects/entities/Author')
|
const oldAuthor = require('../objects/entities/Author')
|
||||||
|
|
||||||
module.exports = (sequelize) => {
|
class Author extends Model {
|
||||||
class Author extends Model {
|
constructor(values, options) {
|
||||||
|
super(values, options)
|
||||||
|
|
||||||
|
/** @type {UUIDV4} */
|
||||||
|
this.id
|
||||||
|
/** @type {string} */
|
||||||
|
this.name
|
||||||
|
/** @type {string} */
|
||||||
|
this.lastFirst
|
||||||
|
/** @type {string} */
|
||||||
|
this.asin
|
||||||
|
/** @type {string} */
|
||||||
|
this.description
|
||||||
|
/** @type {string} */
|
||||||
|
this.imagePath
|
||||||
|
/** @type {UUIDV4} */
|
||||||
|
this.libraryId
|
||||||
|
/** @type {Date} */
|
||||||
|
this.updatedAt
|
||||||
|
/** @type {Date} */
|
||||||
|
this.createdAt
|
||||||
|
}
|
||||||
|
|
||||||
static async getOldAuthors() {
|
static async getOldAuthors() {
|
||||||
const authors = await this.findAll()
|
const authors = await this.findAll()
|
||||||
return authors.map(au => au.getOldAuthor())
|
return authors.map(au => au.getOldAuthor())
|
||||||
@ -60,9 +82,13 @@ module.exports = (sequelize) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Author.init({
|
/**
|
||||||
|
* Initialize model
|
||||||
|
* @param {import('../Database').sequelize} sequelize
|
||||||
|
*/
|
||||||
|
static init(sequelize) {
|
||||||
|
super.init({
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -100,6 +126,6 @@ module.exports = (sequelize) => {
|
|||||||
onDelete: 'CASCADE'
|
onDelete: 'CASCADE'
|
||||||
})
|
})
|
||||||
Author.belongsTo(library)
|
Author.belongsTo(library)
|
||||||
|
}
|
||||||
return Author
|
|
||||||
}
|
}
|
||||||
|
module.exports = Author
|
||||||
|
Loading…
Reference in New Issue
Block a user