145 lines
2.2 KiB
JavaScript
145 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 practice_groups = sequelize.define(
|
|
'practice_groups',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
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,
|
|
},
|
|
);
|
|
|
|
practice_groups.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.practice_groups.hasMany(db.ai_use_cases, {
|
|
as: 'ai_use_cases_practice_group',
|
|
foreignKey: {
|
|
name: 'practice_groupId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.practice_groups.hasMany(db.policies, {
|
|
as: 'policies_practice_group',
|
|
foreignKey: {
|
|
name: 'practice_groupId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.practice_groups.hasMany(db.human_review_checklists, {
|
|
as: 'human_review_checklists_practice_group',
|
|
foreignKey: {
|
|
name: 'practice_groupId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.practice_groups.hasMany(db.workflow_runs, {
|
|
as: 'workflow_runs_practice_group',
|
|
foreignKey: {
|
|
name: 'practice_groupId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.practice_groups.belongsTo(db.users, {
|
|
as: 'lead_user',
|
|
foreignKey: {
|
|
name: 'lead_userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.practice_groups.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.practice_groups.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return practice_groups;
|
|
};
|
|
|
|
|