252 lines
3.0 KiB
JavaScript
252 lines
3.0 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 ocr_jobs = sequelize.define(
|
|
'ocr_jobs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
engine: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"tesseract",
|
|
|
|
|
|
"google_vision",
|
|
|
|
|
|
"aws_textract",
|
|
|
|
|
|
"azure_form_recognizer",
|
|
|
|
|
|
"other"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
mode: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"text_only",
|
|
|
|
|
|
"layout",
|
|
|
|
|
|
"table",
|
|
|
|
|
|
"auto"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
language: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
dpi: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
detect_orientation: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
enhance_image: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"running",
|
|
|
|
|
|
"succeeded",
|
|
|
|
|
|
"failed",
|
|
|
|
|
|
"canceled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
queued_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
finished_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
retry_count: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
error_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
ocr_jobs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.ocr_jobs.hasMany(db.ocr_results, {
|
|
as: 'ocr_results_job',
|
|
foreignKey: {
|
|
name: 'jobId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.ocr_jobs.hasMany(db.usage_records, {
|
|
as: 'usage_records_job',
|
|
foreignKey: {
|
|
name: 'jobId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.ocr_jobs.belongsTo(db.documents, {
|
|
as: 'document',
|
|
foreignKey: {
|
|
name: 'documentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.ocr_jobs.belongsTo(db.users, {
|
|
as: 'requested_by',
|
|
foreignKey: {
|
|
name: 'requested_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.ocr_jobs.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.ocr_jobs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.ocr_jobs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return ocr_jobs;
|
|
};
|
|
|
|
|