276 lines
4.4 KiB
JavaScript
276 lines
4.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 merchant_profiles = sequelize.define(
|
|
'merchant_profiles',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
display_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
legal_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
business_email: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
business_phone: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
tax_number: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
address_line1: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
address_line2: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
city: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
state: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
postal_code: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
country: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
timezone: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
default_currency: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
merchant_profiles.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.categories, {
|
|
as: 'categories_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.budgets, {
|
|
as: 'budgets_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.transactions, {
|
|
as: 'transactions_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.recurring_transaction_rules, {
|
|
as: 'recurring_transaction_rules_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.tasks, {
|
|
as: 'tasks_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.reports, {
|
|
as: 'reports_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.scheduled_reports, {
|
|
as: 'scheduled_reports_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.notifications, {
|
|
as: 'notifications_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.activity_logs, {
|
|
as: 'activity_logs_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.ai_insights, {
|
|
as: 'ai_insights_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.support_conversations, {
|
|
as: 'support_conversations_merchant_profile',
|
|
foreignKey: {
|
|
name: 'merchant_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.merchant_profiles.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.merchant_profiles.hasMany(db.file, {
|
|
as: 'logo',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.merchant_profiles.getTableName(),
|
|
belongsToColumn: 'logo',
|
|
},
|
|
});
|
|
|
|
|
|
db.merchant_profiles.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.merchant_profiles.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return merchant_profiles;
|
|
};
|
|
|
|
|