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

78 lines
1.9 KiB
JavaScript

const { DataTypes, Model } = require("sequelize");
const sequelize = require("../../config/sequelize");
class Comment extends Model { }
const CommentModel = () => {
Comment.init(
{
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
body: {
type: DataTypes.TEXT,
allowNull: false
},
authorId: {
type: DataTypes.STRING(24),
allowNull: true,
references: {
model: 'user',
key: 'id'
}
},
articleId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'article',
key: 'id'
}
}
},
{
sequelize,
tableName: 'comment',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "authorId",
using: "BTREE",
fields: [
{ name: "authorId" },
]
},
{
name: "articleId",
using: "BTREE",
fields: [
{ name: "articleId" },
]
},
]
}
);
Comment.prototype.toJSONFor = function () {
return {
id: this.id,
body: this.body
};
};
return Comment;
};
module.exports = CommentModel;