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 savings_accounts = sequelize.define( 'savings_accounts', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, balance: { type: DataTypes.DECIMAL, }, account_type: { type: DataTypes.ENUM, values: ['Regular', 'TimeDeposit', 'Youth'], }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); savings_accounts.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.savings_accounts.belongsTo(db.members, { as: 'member', foreignKey: { name: 'memberId', }, constraints: false, }); db.savings_accounts.belongsTo(db.branches, { as: 'branches', foreignKey: { name: 'branchesId', }, constraints: false, }); db.savings_accounts.belongsTo(db.users, { as: 'createdBy', }); db.savings_accounts.belongsTo(db.users, { as: 'updatedBy', }); }; return savings_accounts; };