38906-vm/backend/src/db/models/economic_events.js
2026-03-01 10:33:29 +00:00

170 lines
1.9 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 economic_events = sequelize.define(
'economic_events',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
country: {
type: DataTypes.TEXT,
},
impact: {
type: DataTypes.ENUM,
values: [
"low",
"medium",
"high"
],
},
starts_at: {
type: DataTypes.DATE,
},
ends_at: {
type: DataTypes.DATE,
},
actual_value: {
type: DataTypes.DECIMAL,
},
forecast_value: {
type: DataTypes.DECIMAL,
},
previous_value: {
type: DataTypes.DECIMAL,
},
unit: {
type: DataTypes.TEXT,
},
source: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
economic_events.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.economic_events.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.economic_events.belongsTo(db.users, {
as: 'createdBy',
});
db.economic_events.belongsTo(db.users, {
as: 'updatedBy',
});
};
return economic_events;
};