Files
adastra_api/src/database/models/mysql/Favorite.js
T
2025-08-15 15:54:13 +02:00

64 lines
1.6 KiB
JavaScript

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;