40008-vm/backend/src/db/models/command_catalog.js
2026-05-15 12:02:03 +00:00

163 lines
2.0 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 command_catalog = sequelize.define(
'command_catalog',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
command_name: {
type: DataTypes.TEXT,
},
command_type: {
type: DataTypes.ENUM,
values: [
"block_sites",
"unblock_sites",
"clear_downloads",
"clear_recycle_bin",
"restart_computer",
"lock_computer",
"window_list",
"window_close",
"file_deploy",
"software_install",
"software_uninstall"
],
},
description: {
type: DataTypes.TEXT,
},
script_template: {
type: DataTypes.TEXT,
},
requires_approval: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
is_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
command_catalog.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.command_catalog.hasMany(db.command_jobs, {
as: 'command_jobs_command',
foreignKey: {
name: 'commandId',
},
constraints: false,
});
//end loop
db.command_catalog.belongsTo(db.users, {
as: 'createdBy',
});
db.command_catalog.belongsTo(db.users, {
as: 'updatedBy',
});
};
return command_catalog;
};