234 lines
2.8 KiB
JavaScript
234 lines
2.8 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 providers = sequelize.define(
|
|
'providers',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
slug: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
provider_kind: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"api",
|
|
|
|
|
|
"scraper",
|
|
|
|
|
|
"tool_connector"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
base_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
documentation_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
auth_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"api_key",
|
|
|
|
|
|
"bearer",
|
|
|
|
|
|
"basic",
|
|
|
|
|
|
"oauth2",
|
|
|
|
|
|
"none"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"active",
|
|
|
|
|
|
"disabled",
|
|
|
|
|
|
"deprecated"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
rate_limit_per_minute: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
stores_pii: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
providers.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.providers.hasMany(db.provider_credentials, {
|
|
as: 'provider_credentials_provider',
|
|
foreignKey: {
|
|
name: 'providerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.providers.hasMany(db.lookup_jobs, {
|
|
as: 'lookup_jobs_provider',
|
|
foreignKey: {
|
|
name: 'providerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.providers.hasMany(db.lookup_results, {
|
|
as: 'lookup_results_provider',
|
|
foreignKey: {
|
|
name: 'providerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.providers.hasMany(db.locations, {
|
|
as: 'locations_provider',
|
|
foreignKey: {
|
|
name: 'providerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.providers.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.providers.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.providers.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return providers;
|
|
};
|
|
|
|
|