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_batches = sequelize.define( 'payment_batches', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, batch_reference: { type: DataTypes.TEXT, }, total_amount: { type: DataTypes.DECIMAL, }, payment_count: { type: DataTypes.INTEGER, }, batch_date: { type: DataTypes.DATE, }, batch_status: { type: DataTypes.ENUM, values: [ "pending", "accepted", "rejected", "settled" ], }, notes: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); payment_batches.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_batches.belongsTo(db.customers, { as: 'customer', foreignKey: { name: 'customerId', }, constraints: false, }); db.payment_batches.belongsTo(db.users, { as: 'createdBy', }); db.payment_batches.belongsTo(db.users, { as: 'updatedBy', }); }; return payment_batches; };