Mise à jour des models mysql

This commit is contained in:
Rampeur
2025-08-15 15:54:13 +02:00
parent 8a011af73a
commit bd3d1ade49
14 changed files with 633 additions and 156 deletions
+63
View File
@@ -0,0 +1,63 @@
const { DataTypes, Model } = require("sequelize");
const sequelize = require("../../config/sequelize");
class Favorite extends Model { }
const FavoriteModel = () => {
Favorite.init(
{
userId: {
type: DataTypes.STRING(24),
allowNull: false,
primaryKey: true,
references: {
model: 'user',
key: 'id'
}
},
articleId: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
references: {
model: 'article',
key: 'id'
}
}
},
{
sequelize,
tableName: 'favorite',
timestamps: false,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "userId" },
{ name: "articleId" },
]
},
{
name: "articleId",
using: "BTREE",
fields: [
{ name: "articleId" },
]
},
]
}
);
Favorite.prototype.toJSONFor = function () {
return {
userId: this.userId,
articleId: this.articleId
};
};
return Favorite;
};
module.exports = FavoriteModel;