154 lines
1.9 KiB
JavaScript
154 lines
1.9 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 session_exports = sequelize.define(
|
|
'session_exports',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
export_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"decision_document_pdf",
|
|
|
|
|
|
"decision_document_markdown",
|
|
|
|
|
|
"boardroom_memo_pdf",
|
|
|
|
|
|
"full_session_json"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"requested",
|
|
|
|
|
|
"generated",
|
|
|
|
|
|
"failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
requested_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
generated_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
error_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
session_exports.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.session_exports.belongsTo(db.sessions, {
|
|
as: 'session',
|
|
foreignKey: {
|
|
name: 'sessionId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.session_exports.hasMany(db.file, {
|
|
as: 'export_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.session_exports.getTableName(),
|
|
belongsToColumn: 'export_file',
|
|
},
|
|
});
|
|
|
|
|
|
db.session_exports.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.session_exports.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return session_exports;
|
|
};
|
|
|
|
|