214 lines
2.3 KiB
JavaScript
214 lines
2.3 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const alerts = sequelize.define(
|
|
'alerts',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
channel: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"in_app",
|
|
|
|
|
|
"email",
|
|
|
|
|
|
"webhook"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
trigger_kind: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"scan_completed",
|
|
|
|
|
|
"signal_score_above",
|
|
|
|
|
|
"signal_type_detected",
|
|
|
|
|
|
"ticker_event"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
min_score: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
signal_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"any",
|
|
|
|
|
|
"trend_shift",
|
|
|
|
|
|
"unusual_volume",
|
|
|
|
|
|
"volatility_spike",
|
|
|
|
|
|
"breakout",
|
|
|
|
|
|
"mean_reversion",
|
|
|
|
|
|
"sentiment_vs_fundamentals",
|
|
|
|
|
|
"crowded_trade",
|
|
|
|
|
|
"short_candidate",
|
|
|
|
|
|
"narrative_risk"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
is_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
webhook_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
last_triggered_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
alerts.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.alerts.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.alerts.belongsTo(db.watchlists, {
|
|
as: 'watchlist',
|
|
foreignKey: {
|
|
name: 'watchlistId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.alerts.belongsTo(db.scan_templates, {
|
|
as: 'scan_template',
|
|
foreignKey: {
|
|
name: 'scan_templateId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.alerts.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.alerts.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return alerts;
|
|
};
|
|
|
|
|