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 upload_links = sequelize.define( 'upload_links', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, token: { type: DataTypes.TEXT, }, expires_at: { type: DataTypes.DATE, }, is_used: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); upload_links.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.upload_links.belongsTo(db.credits, { as: 'credit', foreignKey: { name: 'creditId', }, constraints: false, }); db.upload_links.belongsTo(db.users, { as: 'user', foreignKey: { name: 'userId', }, constraints: false, }); db.upload_links.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.upload_links.belongsTo(db.users, { as: 'createdBy', }); db.upload_links.belongsTo(db.users, { as: 'updatedBy', }); }; return upload_links; };