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 test_trans = sequelize.define( 'test_trans', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, result: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); test_trans.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.test_trans.belongsTo(db.visits, { as: 'visit', foreignKey: { name: 'visitId', }, constraints: false, }); db.test_trans.belongsTo(db.test_types, { as: 'test_type', foreignKey: { name: 'test_typeId', }, constraints: false, }); db.test_trans.belongsTo(db.group_types, { as: 'group_type', foreignKey: { name: 'group_typeId', }, constraints: false, }); db.test_trans.belongsTo(db.test_descs, { as: 'test_desc', foreignKey: { name: 'test_descId', }, constraints: false, }); db.test_trans.belongsTo(db.organization, { as: 'organization', foreignKey: { name: 'organizationId', }, constraints: false, }); db.test_trans.belongsTo(db.users, { as: 'createdBy', }); db.test_trans.belongsTo(db.users, { as: 'updatedBy', }); }; return test_trans; };