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 ai_jobs = sequelize.define( 'ai_jobs', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, job_type: { type: DataTypes.ENUM, values: [ "drafting", "file_analysis", "legal_research", "citator", "transcription", "translation", "medical_chronology", "causation", "ocr", "export" ], }, status: { type: DataTypes.ENUM, values: [ "queued", "running", "completed", "failed", "canceled" ], }, input_summary: { type: DataTypes.TEXT, }, output_summary: { type: DataTypes.TEXT, }, cost_usd: { type: DataTypes.DECIMAL, }, queued_at: { type: DataTypes.DATE, }, started_at: { type: DataTypes.DATE, }, completed_at: { type: DataTypes.DATE, }, error_message: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); ai_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.ai_jobs.belongsTo(db.users, { as: 'requested_by', foreignKey: { name: 'requested_byId', }, constraints: false, }); db.ai_jobs.belongsTo(db.matters, { as: 'matter', foreignKey: { name: 'matterId', }, constraints: false, }); db.ai_jobs.belongsTo(db.files, { as: 'file', foreignKey: { name: 'fileId', }, constraints: false, }); db.ai_jobs.belongsTo(db.users, { as: 'createdBy', }); db.ai_jobs.belongsTo(db.users, { as: 'updatedBy', }); }; return ai_jobs; };