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 influencers = sequelize.define( 'influencers', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, social_media: { type: DataTypes.TEXT, }, niches: { type: DataTypes.TEXT, }, average_reach: { type: DataTypes.DECIMAL, }, pix_key: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); influencers.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity db.influencers.hasMany(db.contracts, { as: 'contracts_influencer', foreignKey: { name: 'influencerId', }, constraints: false, }); //end loop db.influencers.belongsTo(db.users, { as: 'user', foreignKey: { name: 'userId', }, constraints: false, }); db.influencers.belongsTo(db.companies, { as: 'companies', foreignKey: { name: 'companiesId', }, constraints: false, }); db.influencers.hasMany(db.file, { as: 'profile_picture', foreignKey: 'belongsToId', constraints: false, scope: { belongsTo: db.influencers.getTableName(), belongsToColumn: 'profile_picture', }, }); db.influencers.belongsTo(db.users, { as: 'createdBy', }); db.influencers.belongsTo(db.users, { as: 'updatedBy', }); }; return influencers; };