154 lines
2.3 KiB
JavaScript
154 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 portfolios = sequelize.define(
|
|
'portfolios',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
currency: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
portfolios.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.portfolios.hasMany(db.holdings, {
|
|
as: 'holdings_portfolio',
|
|
foreignKey: {
|
|
name: 'portfolioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.portfolios.hasMany(db.transactions, {
|
|
as: 'transactions_portfolio',
|
|
foreignKey: {
|
|
name: 'portfolioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.portfolios.hasMany(db.dividend_events, {
|
|
as: 'dividend_events_portfolio',
|
|
foreignKey: {
|
|
name: 'portfolioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
db.portfolios.hasMany(db.portfolio_valuations, {
|
|
as: 'portfolio_valuations_portfolio',
|
|
foreignKey: {
|
|
name: 'portfolioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.portfolios.hasMany(db.allocation_targets, {
|
|
as: 'allocation_targets_portfolio',
|
|
foreignKey: {
|
|
name: 'portfolioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.portfolios.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.portfolios.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.portfolios.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return portfolios;
|
|
};
|
|
|
|
|