duckil_plm/fems-api/src/models/Alert.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-11-02 18:01:31 +09:00
// src/models/Alert.js
const { Model, DataTypes } = require("sequelize");
class Alert extends Model {
static init(sequelize) {
super.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
type: {
type: DataTypes.ENUM("error", "warning", "info"),
allowNull: false,
},
message: {
type: DataTypes.STRING,
allowNull: false,
},
read: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
companyId: {
type: DataTypes.UUID,
allowNull: false,
},
branchId: {
type: DataTypes.UUID,
allowNull: true,
},
},
{
sequelize,
modelName: "Alert",
tableName: "alerts",
timestamps: true,
}
);
return this;
}
static associate(models) {
this.belongsTo(models.Company, { foreignKey: "companyId" });
this.belongsTo(models.Branch, { foreignKey: "branchId" });
}
}
module.exports = Alert;