234 lines
2.7 KiB
JavaScript
234 lines
2.7 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 csv_jobs = sequelize.define(
|
|
'csv_jobs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
job_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"import",
|
|
|
|
|
|
"export"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
entity_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"products",
|
|
|
|
|
|
"customers",
|
|
|
|
|
|
"orders"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"running",
|
|
|
|
|
|
"completed",
|
|
|
|
|
|
"failed",
|
|
|
|
|
|
"canceled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
source_filename: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
total_rows: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
processed_rows: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
success_rows: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
error_rows: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
error_report: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
finished_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
csv_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.csv_jobs.belongsTo(db.users, {
|
|
as: 'requested_by',
|
|
foreignKey: {
|
|
name: 'requested_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.csv_jobs.belongsTo(db.organizations, {
|
|
as: 'organization',
|
|
foreignKey: {
|
|
name: 'organizationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.csv_jobs.hasMany(db.file, {
|
|
as: 'source_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.csv_jobs.getTableName(),
|
|
belongsToColumn: 'source_file',
|
|
},
|
|
});
|
|
|
|
db.csv_jobs.hasMany(db.file, {
|
|
as: 'result_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.csv_jobs.getTableName(),
|
|
belongsToColumn: 'result_file',
|
|
},
|
|
});
|
|
|
|
|
|
db.csv_jobs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.csv_jobs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return csv_jobs;
|
|
};
|
|
|
|
|