31835/backend/src/db/models/financials.js
2025-05-28 23:56:00 +00:00

68 lines
1.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 financials = sequelize.define(
'financials',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
account_name: {
type: DataTypes.TEXT,
},
balance: {
type: DataTypes.DECIMAL,
},
currency: {
type: DataTypes.ENUM,
values: ['USD', 'EUR', 'GBP'],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
financials.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.financials.belongsTo(db.companies, {
as: 'companies',
foreignKey: {
name: 'companiesId',
},
constraints: false,
});
db.financials.belongsTo(db.users, {
as: 'createdBy',
});
db.financials.belongsTo(db.users, {
as: 'updatedBy',
});
};
return financials;
};