Initial commit

This commit is contained in:
2025-08-16 19:43:44 +02:00
commit ea9a2627b4
64 changed files with 9232 additions and 0 deletions

109
server/models/AlertLog.js Normal file
View File

@@ -0,0 +1,109 @@
const { DataTypes } = require('sequelize');
module.exports = (sequelize) => {
const AlertLog = sequelize.define('AlertLog', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
alert_rule_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'alert_rules',
key: 'id'
}
},
detection_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'drone_detections',
key: 'id'
}
},
alert_type: {
type: DataTypes.ENUM('sms', 'email', 'webhook', 'push'),
allowNull: false
},
recipient: {
type: DataTypes.STRING,
allowNull: false,
comment: 'Phone number, email, or webhook URL'
},
message: {
type: DataTypes.TEXT,
allowNull: false,
comment: 'Alert message content'
},
status: {
type: DataTypes.ENUM('pending', 'sent', 'failed', 'delivered'),
defaultValue: 'pending'
},
sent_at: {
type: DataTypes.DATE,
allowNull: true
},
delivered_at: {
type: DataTypes.DATE,
allowNull: true
},
error_message: {
type: DataTypes.TEXT,
allowNull: true,
comment: 'Error message if alert failed'
},
external_id: {
type: DataTypes.STRING,
allowNull: true,
comment: 'External service message ID (Twilio SID, etc.)'
},
cost: {
type: DataTypes.DECIMAL(6, 4),
allowNull: true,
comment: 'Cost of sending the alert (for SMS, etc.)'
},
retry_count: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: 'Number of retry attempts'
},
priority: {
type: DataTypes.ENUM('low', 'medium', 'high', 'critical'),
defaultValue: 'medium'
},
created_at: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW
},
updated_at: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW
}
}, {
tableName: 'alert_logs',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
indexes: [
{
fields: ['alert_rule_id']
},
{
fields: ['detection_id']
},
{
fields: ['status']
},
{
fields: ['sent_at']
},
{
fields: ['alert_type', 'status']
}
]
});
return AlertLog;
};