mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-09 10:51:37 +00:00
Added Explicit user book rating + Community rating
This commit is contained in:
parent
3bfd9f419c
commit
dba575761e
16 changed files with 426 additions and 64 deletions
54
server/models/UserBookExplicitRating.js
Normal file
54
server/models/UserBookExplicitRating.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue