Added Explicit user book rating + Community rating

This commit is contained in:
Peter BALIVET 2025-06-30 13:52:37 +02:00
parent 3bfd9f419c
commit dba575761e
16 changed files with 426 additions and 64 deletions

View 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