30356/backend/src/db/models/investments.js
2025-03-31 18:07:30 +00:00

70 lines
1.4 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 investments = sequelize.define(
'investments',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
investment_id: {
type: DataTypes.TEXT,
},
amount: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
investments.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.investments.belongsTo(db.users, {
as: 'investor',
foreignKey: {
name: 'investorId',
},
constraints: false,
});
db.investments.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.investments.belongsTo(db.users, {
as: 'createdBy',
});
db.investments.belongsTo(db.users, {
as: 'updatedBy',
});
};
return investments;
};