38631-vm/backend/src/db/models/curation_actions.js
2026-02-20 00:45:34 +00:00

220 lines
2.4 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 curation_actions = sequelize.define(
'curation_actions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
target_type: {
type: DataTypes.ENUM,
values: [
"requirement",
"artifact",
"statement",
"subtopic",
"chunk"
],
},
target_key: {
type: DataTypes.TEXT,
},
action: {
type: DataTypes.ENUM,
values: [
"approve",
"reject",
"edit",
"comment"
],
},
reason_code: {
type: DataTypes.ENUM,
values: [
"insufficient_provenance",
"not_testable",
"duplicate",
"conflict_detected",
"wrong_category",
"template_invalid",
"needs_clarification",
"scope_mismatch",
"other"
],
},
comment: {
type: DataTypes.TEXT,
},
before_text: {
type: DataTypes.TEXT,
},
after_text: {
type: DataTypes.TEXT,
},
action_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
curation_actions.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.curation_actions.belongsTo(db.tenants, {
as: 'tenant',
foreignKey: {
name: 'tenantId',
},
constraints: false,
});
db.curation_actions.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.curation_actions.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.curation_actions.belongsTo(db.users, {
as: 'createdBy',
});
db.curation_actions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return curation_actions;
};