38852-vm/backend/src/db/models/opportunities.js
2026-02-28 20:55:43 +00:00

219 lines
2.5 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 opportunities = sequelize.define(
'opportunities',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
signal: {
type: DataTypes.ENUM,
values: [
"buy",
"hold",
"sell",
"watch"
],
},
status: {
type: DataTypes.ENUM,
values: [
"new",
"reviewing",
"shortlisted",
"dismissed",
"acted"
],
},
identified_at: {
type: DataTypes.DATE,
},
expires_at: {
type: DataTypes.DATE,
},
score_total: {
type: DataTypes.DECIMAL,
},
score_value: {
type: DataTypes.DECIMAL,
},
score_growth: {
type: DataTypes.DECIMAL,
},
score_quality: {
type: DataTypes.DECIMAL,
},
score_momentum: {
type: DataTypes.DECIMAL,
},
summary: {
type: DataTypes.TEXT,
},
key_drivers: {
type: DataTypes.TEXT,
},
is_bookmarked: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
opportunities.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.opportunities.belongsTo(db.assets, {
as: 'asset',
foreignKey: {
name: 'assetId',
},
constraints: false,
});
db.opportunities.belongsTo(db.screening_strategies, {
as: 'strategy',
foreignKey: {
name: 'strategyId',
},
constraints: false,
});
db.opportunities.belongsTo(db.scoring_models, {
as: 'scoring_model',
foreignKey: {
name: 'scoring_modelId',
},
constraints: false,
});
db.opportunities.belongsTo(db.users, {
as: 'createdBy',
});
db.opportunities.belongsTo(db.users, {
as: 'updatedBy',
});
};
return opportunities;
};