240 lines
3.2 KiB
JavaScript
240 lines
3.2 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 simulation_runs = sequelize.define(
|
|
'simulation_runs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
run_label: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
ran_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
scenario_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"bnpl",
|
|
|
|
|
|
"installment",
|
|
|
|
|
|
"loan",
|
|
|
|
|
|
"credit_card_purchase"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
purchase_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
down_payment_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
term_months: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
apr_percent: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
fees_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
pre_utilization_percent: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
post_utilization_percent: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
score_impact_low_points: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
score_impact_high_points: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_interest_estimate: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
debt_free_delay_days: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
savings_goal_delay_days: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
primary_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
simulation_runs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.simulation_runs.hasMany(db.intervention_decisions, {
|
|
as: 'intervention_decisions_simulation_run',
|
|
foreignKey: {
|
|
name: 'simulation_runId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.simulation_runs.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.simulation_runs.belongsTo(db.financial_profiles, {
|
|
as: 'financial_profile',
|
|
foreignKey: {
|
|
name: 'financial_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.simulation_runs.belongsTo(db.detection_events, {
|
|
as: 'detection_event',
|
|
foreignKey: {
|
|
name: 'detection_eventId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.simulation_runs.belongsTo(db.simulation_assumptions, {
|
|
as: 'assumption_set',
|
|
foreignKey: {
|
|
name: 'assumption_setId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.simulation_runs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.simulation_runs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return simulation_runs;
|
|
};
|
|
|
|
|