2025-07-04 17:40:39 +00:00

154 lines
3.3 KiB
JavaScript

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 tools = sequelize.define(
'tools',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
category: {
type: DataTypes.ENUM,
values: ['ide', 'in_browser_code', 'ai_assistant'],
},
free_tier_available: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
credit_card_required: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
tools.associate = (db) => {
db.tools.belongsToMany(db.features, {
as: 'features',
foreignKey: {
name: 'tools_featuresId',
},
constraints: false,
through: 'toolsFeaturesFeatures',
});
db.tools.belongsToMany(db.features, {
as: 'features_filter',
foreignKey: {
name: 'tools_featuresId',
},
constraints: false,
through: 'toolsFeaturesFeatures',
});
db.tools.belongsToMany(db.pros_cons, {
as: 'pros_cons',
foreignKey: {
name: 'tools_pros_consId',
},
constraints: false,
through: 'toolsPros_consPros_cons',
});
db.tools.belongsToMany(db.pros_cons, {
as: 'pros_cons_filter',
foreignKey: {
name: 'tools_pros_consId',
},
constraints: false,
through: 'toolsPros_consPros_cons',
});
db.tools.belongsToMany(db.pricing_models, {
as: 'pricing_models',
foreignKey: {
name: 'tools_pricing_modelsId',
},
constraints: false,
through: 'toolsPricing_modelsPricing_models',
});
db.tools.belongsToMany(db.pricing_models, {
as: 'pricing_models_filter',
foreignKey: {
name: 'tools_pricing_modelsId',
},
constraints: false,
through: 'toolsPricing_modelsPricing_models',
});
db.tools.belongsToMany(db.integrations, {
as: 'integrations',
foreignKey: {
name: 'tools_integrationsId',
},
constraints: false,
through: 'toolsIntegrationsIntegrations',
});
db.tools.belongsToMany(db.integrations, {
as: 'integrations_filter',
foreignKey: {
name: 'tools_integrationsId',
},
constraints: false,
through: 'toolsIntegrationsIntegrations',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.tools.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.tools.belongsTo(db.users, {
as: 'createdBy',
});
db.tools.belongsTo(db.users, {
as: 'updatedBy',
});
};
return tools;
};