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 ai_services = sequelize.define( 'ai_services', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, description: { type: DataTypes.TEXT, }, price: { type: DataTypes.DECIMAL, }, type: { type: DataTypes.ENUM, values: ['AITool', 'AIStudio', 'Voicebot', 'Chatbot'], }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); ai_services.associate = (db) => { db.ai_services.belongsToMany(db.categories, { as: 'categories', foreignKey: { name: 'ai_services_categoriesId', }, constraints: false, through: 'ai_servicesCategoriesCategories', }); db.ai_services.belongsToMany(db.categories, { as: 'categories_filter', foreignKey: { name: 'ai_services_categoriesId', }, constraints: false, through: 'ai_servicesCategoriesCategories', }); db.ai_services.belongsToMany(db.orders, { as: 'orders', foreignKey: { name: 'ai_services_ordersId', }, constraints: false, through: 'ai_servicesOrdersOrders', }); db.ai_services.belongsToMany(db.orders, { as: 'orders_filter', foreignKey: { name: 'ai_services_ordersId', }, constraints: false, through: 'ai_servicesOrdersOrders', }); /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.ai_services.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.ai_services.belongsTo(db.users, { as: 'createdBy', }); db.ai_services.belongsTo(db.users, { as: 'updatedBy', }); }; return ai_services; };