mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-09 10:51:37 +00:00
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
const { DataTypes, Model } = require('sequelize')
|
|
|
|
class UserBookExplicitRating extends Model {
|
|
static init(sequelize) {
|
|
super.init(
|
|
{
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true
|
|
},
|
|
userId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
bookId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
rating: {
|
|
type: DataTypes.FLOAT,
|
|
allowNull: false
|
|
}
|
|
},
|
|
{
|
|
sequelize,
|
|
modelName: 'userBookExplicitRating',
|
|
tableName: 'userBookExplicitRatings',
|
|
indexes: [
|
|
{
|
|
unique: true,
|
|
fields: ['userId', 'bookId']
|
|
}
|
|
]
|
|
}
|
|
)
|
|
|
|
const { user, book } = sequelize.models
|
|
|
|
user.hasMany(UserBookExplicitRating, {
|
|
foreignKey: 'userId'
|
|
})
|
|
|
|
this.belongsTo(user, { foreignKey: 'userId' })
|
|
|
|
book.hasMany(this, {
|
|
foreignKey: 'bookId'
|
|
})
|
|
|
|
this.belongsTo(book, { foreignKey: 'bookId' })
|
|
}
|
|
}
|
|
|
|
module.exports = UserBookExplicitRating
|