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 tool_entitlements = sequelize.define( 'tool_entitlements', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, entitlement_status: { type: DataTypes.ENUM, values: [ "allowed", "restricted", "revoked" ], }, effective_from: { type: DataTypes.DATE, }, effective_to: { type: DataTypes.DATE, }, restriction_reason: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); tool_entitlements.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.tool_entitlements.belongsTo(db.users, { as: 'user', foreignKey: { name: 'userId', }, constraints: false, }); db.tool_entitlements.belongsTo(db.ai_tools, { as: 'tool', foreignKey: { name: 'toolId', }, constraints: false, }); db.tool_entitlements.belongsTo(db.users, { as: 'createdBy', }); db.tool_entitlements.belongsTo(db.users, { as: 'updatedBy', }); }; return tool_entitlements; };