90 lines
1.8 KiB
JavaScript
90 lines
1.8 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 narratives = sequelize.define(
|
|
'narratives',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
concept_qname: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
value_text: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
note: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
narratives.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.narratives.belongsTo(db.projects, {
|
|
as: 'project',
|
|
foreignKey: {
|
|
name: 'projectId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.narratives.belongsTo(db.contexts, {
|
|
as: 'context',
|
|
foreignKey: {
|
|
name: 'contextId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.narratives.belongsTo(db.evidence_files, {
|
|
as: 'source_ref',
|
|
foreignKey: {
|
|
name: 'source_refId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.narratives.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.narratives.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.narratives.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return narratives;
|
|
};
|