170 lines
2.2 KiB
JavaScript
170 lines
2.2 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 merchants = sequelize.define(
|
|
'merchants',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
domain: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
merchant_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"retail",
|
|
|
|
|
|
"digital",
|
|
|
|
|
|
"subscription",
|
|
|
|
|
|
"services",
|
|
|
|
|
|
"unknown"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
is_blocked: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_allowed: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
merchants.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.merchants.hasMany(db.transactions, {
|
|
as: 'transactions_merchant',
|
|
foreignKey: {
|
|
name: 'merchantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchants.hasMany(db.subscriptions, {
|
|
as: 'subscriptions_merchant',
|
|
foreignKey: {
|
|
name: 'merchantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.merchants.hasMany(db.pause_checks, {
|
|
as: 'pause_checks_merchant',
|
|
foreignKey: {
|
|
name: 'merchantId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.merchants.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.merchants.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.merchants.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return merchants;
|
|
};
|
|
|
|
|