170 lines
2.0 KiB
JavaScript
170 lines
2.0 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 geopolitical_scores = sequelize.define(
|
|
'geopolitical_scores',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
as_of_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
score_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"news_sentiment",
|
|
|
|
|
|
"event_intensity",
|
|
|
|
|
|
"expert_overlay",
|
|
|
|
|
|
"composite_risk"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
horizon: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"intraday",
|
|
|
|
|
|
"daily",
|
|
|
|
|
|
"weekly",
|
|
|
|
|
|
"monthly"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
score_value: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
iran_conflict_weight: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
methodology_note: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
geopolitical_scores.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.geopolitical_scores.belongsTo(db.geopolitical_events, {
|
|
as: 'related_event',
|
|
foreignKey: {
|
|
name: 'related_eventId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.geopolitical_scores.belongsTo(db.data_sources, {
|
|
as: 'data_source',
|
|
foreignKey: {
|
|
name: 'data_sourceId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.geopolitical_scores.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.geopolitical_scores.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return geopolitical_scores;
|
|
};
|
|
|
|
|