38862-vm/backend/src/db/models/legal_topics.js
2026-02-28 15:54:31 +00:00

214 lines
2.6 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 legal_topics = sequelize.define(
'legal_topics',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
category: {
type: DataTypes.ENUM,
values: [
"company_formation",
"contracts",
"employment",
"ip",
"privacy",
"security",
"tax",
"fundraising",
"compliance",
"operations",
"other"
],
},
complexity: {
type: DataTypes.ENUM,
values: [
"low",
"medium",
"high"
],
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
legal_topics.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.legal_topics.hasMany(db.questionnaires, {
as: 'questionnaires_topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
db.legal_topics.hasMany(db.legal_tasks, {
as: 'legal_tasks_topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
db.legal_topics.hasMany(db.document_templates, {
as: 'document_templates_topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
db.legal_topics.hasMany(db.risk_items, {
as: 'risk_items_topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
db.legal_topics.hasMany(db.resource_links, {
as: 'resource_links_topic',
foreignKey: {
name: 'topicId',
},
constraints: false,
});
//end loop
db.legal_topics.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.legal_topics.belongsTo(db.users, {
as: 'createdBy',
});
db.legal_topics.belongsTo(db.users, {
as: 'updatedBy',
});
};
return legal_topics;
};