39054-vm/backend/src/db/models/ai_recommendations.js
2026-03-08 20:32:56 +00:00

189 lines
2.2 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 ai_recommendations = sequelize.define(
'ai_recommendations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
generated_at: {
type: DataTypes.DATE,
},
recommendation_type: {
type: DataTypes.ENUM,
values: [
"containment",
"hardening",
"hunting_query",
"policy_change",
"patching",
"user_training",
"architecture_change"
],
},
status: {
type: DataTypes.ENUM,
values: [
"new",
"accepted",
"rejected",
"implemented"
],
},
estimated_risk_reduction: {
type: DataTypes.DECIMAL,
},
title: {
type: DataTypes.TEXT,
},
details: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
ai_recommendations.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.ai_recommendations.belongsTo(db.organizations, {
as: 'organization',
foreignKey: {
name: 'organizationId',
},
constraints: false,
});
db.ai_recommendations.belongsTo(db.incidents, {
as: 'incident',
foreignKey: {
name: 'incidentId',
},
constraints: false,
});
db.ai_recommendations.belongsTo(db.ai_models, {
as: 'model',
foreignKey: {
name: 'modelId',
},
constraints: false,
});
db.ai_recommendations.belongsTo(db.users, {
as: 'createdBy',
});
db.ai_recommendations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return ai_recommendations;
};