37803-vm/backend/src/db/models/sparx_integrations.js
2026-01-25 12:26:17 +00:00

112 lines
1.7 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 sparx_integrations = sequelize.define(
'sparx_integrations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
sparx_account_uid: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
sparx_integrations.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.sparx_integrations.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.sparx_integrations.hasMany(db.file, {
as: 'config_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.sparx_integrations.getTableName(),
belongsToColumn: 'config_files',
},
});
db.sparx_integrations.belongsTo(db.users, {
as: 'createdBy',
});
db.sparx_integrations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return sparx_integrations;
};