193 lines
2.2 KiB
JavaScript
193 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 intel_reports = sequelize.define(
|
|
'intel_reports',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
source_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"satellite",
|
|
|
|
|
|
"uav",
|
|
|
|
|
|
"sigint",
|
|
|
|
|
|
"humint",
|
|
|
|
|
|
"osint",
|
|
|
|
|
|
"recon",
|
|
|
|
|
|
"cyber"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
confidence: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"low",
|
|
|
|
|
|
"medium",
|
|
|
|
|
|
"high"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
reported_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
x: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
y: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
content: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
intel_reports.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.intel_reports.belongsTo(db.scenarios, {
|
|
as: 'scenario',
|
|
foreignKey: {
|
|
name: 'scenarioId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.intel_reports.belongsTo(db.users, {
|
|
as: 'author',
|
|
foreignKey: {
|
|
name: 'authorId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.intel_reports.hasMany(db.file, {
|
|
as: 'attachments',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.intel_reports.getTableName(),
|
|
belongsToColumn: 'attachments',
|
|
},
|
|
});
|
|
|
|
|
|
db.intel_reports.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.intel_reports.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return intel_reports;
|
|
};
|
|
|
|
|