38848-vm/backend/src/db/models/credit_accounts.js
2026-02-28 12:06:56 +00:00

175 lines
2.1 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 credit_accounts = sequelize.define(
'credit_accounts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
account_name: {
type: DataTypes.TEXT,
},
account_type: {
type: DataTypes.ENUM,
values: [
"credit_card",
"line_of_credit",
"store_card"
],
},
current_balance: {
type: DataTypes.DECIMAL,
},
credit_limit: {
type: DataTypes.DECIMAL,
},
apr_percent: {
type: DataTypes.DECIMAL,
},
minimum_payment_amount: {
type: DataTypes.DECIMAL,
},
minimum_payment_type: {
type: DataTypes.ENUM,
values: [
"fixed_amount",
"percent_of_balance"
],
},
minimum_payment_percent: {
type: DataTypes.DECIMAL,
},
opened_at: {
type: DataTypes.DATE,
},
is_closed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
credit_accounts.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.credit_accounts.belongsTo(db.financial_profiles, {
as: 'financial_profile',
foreignKey: {
name: 'financial_profileId',
},
constraints: false,
});
db.credit_accounts.belongsTo(db.users, {
as: 'createdBy',
});
db.credit_accounts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return credit_accounts;
};