39007-vm/backend/src/db/models/pattern_library.js
2026-03-05 11:58:17 +00:00

144 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 pattern_library = sequelize.define(
'pattern_library',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
pattern_name: {
type: DataTypes.TEXT,
},
category: {
type: DataTypes.ENUM,
values: [
"delay",
"execution",
"positioning",
"psychology",
"operations",
"offer",
"other"
],
},
trigger: {
type: DataTypes.TEXT,
},
correction: {
type: DataTypes.TEXT,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
pattern_library.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.pattern_library.belongsTo(db.workspaces, {
as: 'workspace',
foreignKey: {
name: 'workspaceId',
},
constraints: false,
});
db.pattern_library.belongsTo(db.users, {
as: 'createdBy',
});
db.pattern_library.belongsTo(db.users, {
as: 'updatedBy',
});
};
return pattern_library;
};