Cloudtopiaa_Reseller_Backend/src/models/ServiceAlert.js
2025-07-31 08:15:46 +05:30

89 lines
1.8 KiB
JavaScript

module.exports = (sequelize, DataTypes) => {
const ServiceAlert = sequelize.define('ServiceAlert', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
serviceId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'customer_services',
key: 'id'
}
},
alertType: {
type: DataTypes.ENUM('usage_threshold', 'billing_threshold', 'service_down', 'maintenance', 'expiry_warning'),
allowNull: false
},
severity: {
type: DataTypes.ENUM('low', 'medium', 'high', 'critical'),
allowNull: false,
defaultValue: 'medium'
},
title: {
type: DataTypes.STRING,
allowNull: false
},
message: {
type: DataTypes.TEXT,
allowNull: false
},
status: {
type: DataTypes.ENUM('active', 'acknowledged', 'resolved', 'dismissed'),
allowNull: false,
defaultValue: 'active'
},
threshold: {
type: DataTypes.JSON,
allowNull: true
},
currentValue: {
type: DataTypes.JSON,
allowNull: true
},
acknowledgedAt: {
type: DataTypes.DATE,
allowNull: true
},
resolvedAt: {
type: DataTypes.DATE,
allowNull: true
},
metadata: {
type: DataTypes.JSON,
defaultValue: {}
}
}, {
tableName: 'service_alerts',
indexes: [
{
fields: ['service_id']
},
{
fields: ['alert_type']
},
{
fields: ['severity']
},
{
fields: ['status']
},
{
fields: ['created_at']
}
]
});
// Class methods
ServiceAlert.associate = function(models) {
ServiceAlert.belongsTo(models.CustomerService, {
foreignKey: 'serviceId',
as: 'service'
});
};
return ServiceAlert;
};