38876-vm/backend/src/db/models/payment_allocations.js
2026-02-28 15:33:20 +00:00

132 lines
1.8 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 payment_allocations = sequelize.define(
'payment_allocations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
allocated_amount: {
type: DataTypes.DECIMAL,
},
currency_code: {
type: DataTypes.TEXT,
},
fee_amount: {
type: DataTypes.DECIMAL,
},
fx_rate: {
type: DataTypes.DECIMAL,
},
cashback_amount: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
payment_allocations.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.payment_allocations.belongsTo(db.payment_strategies, {
as: 'payment_strategy',
foreignKey: {
name: 'payment_strategyId',
},
constraints: false,
});
db.payment_allocations.belongsTo(db.financial_accounts, {
as: 'funding_account',
foreignKey: {
name: 'funding_accountId',
},
constraints: false,
});
db.payment_allocations.belongsTo(db.users, {
as: 'createdBy',
});
db.payment_allocations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return payment_allocations;
};