188 lines
2.8 KiB
JavaScript
188 lines
2.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_rules = sequelize.define(
|
|
'payment_rules',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
auto_savings_transfers_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
auto_transfer_max_amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
cashback_routing_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
require_full_statement_payoff: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
fx_optimisation_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
international_transfer_policy: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"always_ask",
|
|
|
|
|
|
"auto_approve_under_threshold",
|
|
|
|
|
|
"never_use"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
international_auto_approve_threshold: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
payment_rules.associate = (db) => {
|
|
|
|
db.payment_rules.belongsToMany(db.spending_categories, {
|
|
as: 'spending_categories',
|
|
foreignKey: {
|
|
name: 'payment_rules_spending_categoriesId',
|
|
},
|
|
constraints: false,
|
|
through: 'payment_rulesSpending_categoriesSpending_categories',
|
|
});
|
|
|
|
db.payment_rules.belongsToMany(db.spending_categories, {
|
|
as: 'spending_categories_filter',
|
|
foreignKey: {
|
|
name: 'payment_rules_spending_categoriesId',
|
|
},
|
|
constraints: false,
|
|
through: 'payment_rulesSpending_categoriesSpending_categories',
|
|
});
|
|
|
|
|
|
/// 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_rules.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.payment_rules.belongsTo(db.financial_accounts, {
|
|
as: 'primary_account',
|
|
foreignKey: {
|
|
name: 'primary_accountId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.payment_rules.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.payment_rules.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return payment_rules;
|
|
};
|
|
|
|
|