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 jobs = sequelize.define( 'jobs', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, type: { type: DataTypes.ENUM, values: ['GENERATE_XBRL', 'VALIDATE_XBRL', 'BUILD_AUDIT_PACK'], }, status: { type: DataTypes.TEXT, }, payload: { type: DataTypes.TEXT, }, result: { type: DataTypes.TEXT, }, started_at: { type: DataTypes.DATE, }, finished_at: { type: DataTypes.DATE, }, error_text: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); jobs.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.jobs.belongsTo(db.projects, { as: 'project', foreignKey: { name: 'projectId', }, constraints: false, }); db.jobs.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.jobs.belongsTo(db.users, { as: 'createdBy', }); db.jobs.belongsTo(db.users, { as: 'updatedBy', }); }; return jobs; };