refs #4823 Changes
This commit is contained in:
parent
c57916815d
commit
38c0a46614
|
@ -1,9 +1,15 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const suppliers = {
|
const suppliers = {
|
||||||
isConnected: {
|
sequenceNumber: {
|
||||||
type: Sequelize.BOOLEAN,
|
type: Sequelize.INTEGER,
|
||||||
defaultValue: false,
|
allowNull: false,
|
||||||
|
},
|
||||||
|
companyGln: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
commercialName: {
|
commercialName: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
|
@ -18,6 +24,19 @@ const suppliers = {
|
||||||
website: {
|
website: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
|
organizationId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
rfhRelationId: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
paymentProviders: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
mailingAddress: {
|
mailingAddress: {
|
||||||
type: Sequelize.JSON,
|
type: Sequelize.JSON,
|
||||||
},
|
},
|
||||||
|
@ -27,31 +46,12 @@ const suppliers = {
|
||||||
pythosanitaryNumber: {
|
pythosanitaryNumber: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
sequenceNumber: {
|
|
||||||
type: Sequelize.INTEGER,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
organizationId: {
|
|
||||||
type: Sequelize.STRING,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
companyGln: {
|
|
||||||
type: Sequelize.STRING,
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: Sequelize.STRING,
|
|
||||||
},
|
|
||||||
endDate: {
|
|
||||||
type: Sequelize.DATE,
|
|
||||||
},
|
|
||||||
rfhRelationId: {
|
|
||||||
type: Sequelize.INTEGER,
|
|
||||||
},
|
|
||||||
organizationType: {
|
organizationType: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
paymentProviders: {
|
isConnected: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
"name": "floriday",
|
"name": "floriday",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
|
||||||
"start": "node index.js",
|
|
||||||
"dev-sync": "FORCE_SYNC=true node --max-old-space-size=4096 index.js",
|
|
||||||
"dev-secrets": "SECRETS=true node --max-old-space-size=4096 index.js",
|
|
||||||
"dev-both": "FORCE_SYNC=true SECRETS=true node --max-old-space-size=4096 index.js",
|
|
||||||
"dev-query": "QUERYSUPPLIERS=true SECRETS=true node --max-old-space-size=4096 index.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cli-progress": "^3.11.2",
|
"cli-progress": "^3.11.2",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
|
|
54
utils.js
54
utils.js
|
@ -4,7 +4,7 @@ import dotenv from 'dotenv';
|
||||||
import { models } from './models/index.js';
|
import { models } from './models/index.js';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import colors from 'colors';
|
import colors from 'colors';
|
||||||
//import cliProgress from 'cli-progress';
|
import cliProgress from 'cli-progress';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +24,7 @@ async function getClientToken() {
|
||||||
const clientConfigData = await models.clientConfig.findAll();
|
const clientConfigData = await models.clientConfig.findAll();
|
||||||
|
|
||||||
if (!clientConfigData[0])
|
if (!clientConfigData[0])
|
||||||
throw colors.red.bold('Token has expired')
|
throw colors.red.bold('No has token')
|
||||||
|
|
||||||
const now = moment().format('YYYY-MM-DD HH:mm:ss');
|
const now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
const tokenExpirationDate = clientConfigData[0].tokenExpiration;
|
const tokenExpirationDate = clientConfigData[0].tokenExpiration;
|
||||||
|
@ -171,10 +171,10 @@ async function asyncQueue(fnArray, concurrency = 1) {
|
||||||
async function syncSequence(current = 0, model = null ,maximumSequenceNumber = 0){
|
async function syncSequence(current = 0, model = null ,maximumSequenceNumber = 0){
|
||||||
if (model == null && current == 0){
|
if (model == null && current == 0){
|
||||||
|
|
||||||
let mockModels = ['suppliers','tradeItems','supplyLines',];
|
let mockModels = ['suppliers','tradeItems','supplyLines'];
|
||||||
|
|
||||||
for (let i = 0; i < mockModels.length; i++) {
|
for (let model in mockModels) {
|
||||||
const element = mockModels[i];
|
const element = mockModels[model];
|
||||||
console.log('Syncing sequence for: ', element);
|
console.log('Syncing sequence for: ', element);
|
||||||
await syncSequence(0, element);
|
await syncSequence(0, element);
|
||||||
}
|
}
|
||||||
|
@ -219,25 +219,27 @@ async function syncSequence(current = 0, model = null ,maximumSequenceNumber = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncSuppliers(){
|
async function syncSuppliers(){
|
||||||
|
const headers = {
|
||||||
let headers = {
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${await getJWT()}`,
|
'Authorization': `Bearer ${await getJWT()}`,
|
||||||
'X-Api-Key': process.env.API_KEY
|
'X-Api-Key': process.env.API_KEY
|
||||||
};
|
};
|
||||||
|
|
||||||
let maximumSequenceNumber = await fetch(`${BASE_CUSTOMER_URL}organizations/current-max-sequence`, {
|
const response = await fetch(`${BASE_CUSTOMER_URL}organizations/current-max-sequence`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
});
|
});
|
||||||
|
const maxSequenceNumber = await response.json();
|
||||||
|
|
||||||
maximumSequenceNumber = await maximumSequenceNumber.json();
|
const progressBar = new cliProgress.SingleBar({
|
||||||
|
format: 'Loading suppliers [{bar}] {percentage}% | {value}/{total}'.cyan,
|
||||||
|
hideCursor: true
|
||||||
|
|
||||||
console.log('Maximum sequence number: ', maximumSequenceNumber);
|
}, cliProgress.Presets.shades_classic);
|
||||||
|
|
||||||
for (let i = 0; i < maximumSequenceNumber; i++) {
|
for (let curSequenceNumber = 0; curSequenceNumber <= maxSequenceNumber; curSequenceNumber++) {
|
||||||
|
|
||||||
let query = `${BASE_CUSTOMER_URL}organizations/sync/${i}?organizationType=SUPPLIER&limit=1000`;
|
let query = `${BASE_CUSTOMER_URL}organizations/sync/${curSequenceNumber}?organizationType=SUPPLIER`;
|
||||||
let response = await fetch(query, {
|
let response = await fetch(query, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
|
@ -246,31 +248,33 @@ async function syncSuppliers(){
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
|
|
||||||
let suppliers = data.results;
|
let suppliers = data.results;
|
||||||
|
|
||||||
for (let supplier of suppliers) {
|
for (let supplier of suppliers) {
|
||||||
i = supplier.sequenceNumber;
|
curSequenceNumber = supplier.sequenceNumber;
|
||||||
|
if (!progressBar.value) {
|
||||||
|
progressBar.start(maxSequenceNumber, curSequenceNumber);
|
||||||
|
}
|
||||||
await models.supplier.upsert({
|
await models.supplier.upsert({
|
||||||
isConnected: false,
|
sequenceNumber: supplier.sequenceNumber,
|
||||||
|
companyGln: supplier.companyGln,
|
||||||
|
name: supplier.name,
|
||||||
commercialName: supplier.commercialName,
|
commercialName: supplier.commercialName,
|
||||||
email: supplier.email,
|
email: supplier.email,
|
||||||
phone: supplier.phone,
|
phone: supplier.phone,
|
||||||
website: supplier.website,
|
website: supplier.website,
|
||||||
|
organizationId: supplier.organizationId,
|
||||||
|
rfhRelationId: supplier.rfhRelationId,
|
||||||
|
paymentProviders: `${supplier.paymentProviders}`,
|
||||||
|
endDate: supplier.endDate,
|
||||||
mailingAddress: supplier.mailingAddress,
|
mailingAddress: supplier.mailingAddress,
|
||||||
physicalAddress: supplier.physicalAddress,
|
physicalAddress: supplier.physicalAddress,
|
||||||
pythosanitaryNumber: supplier.pythosanitaryNumber,
|
pythosanitaryNumber: supplier.pythosanitaryNumber,
|
||||||
sequenceNumber: supplier.sequenceNumber,
|
organizationType: supplier.organizationType
|
||||||
organizationId: supplier.organizationId,
|
|
||||||
companyGln: supplier.companyGln,
|
|
||||||
name: supplier.name,
|
|
||||||
endDate: supplier.endDate,
|
|
||||||
rfhRelationId: supplier.rfhRelationId,
|
|
||||||
organizationType: supplier.organizationType,
|
|
||||||
paymentProviders: `${supplier.paymentProviders}`,
|
|
||||||
});
|
});
|
||||||
console.log('INSERTED:\t', supplier.commercialName, '\nsequenceNumber:\t', supplier.sequenceNumber);
|
progressBar.update(curSequenceNumber);
|
||||||
}
|
}
|
||||||
await syncSequence(i, 'suppliers', maximumSequenceNumber);
|
await syncSequence(curSequenceNumber, 'suppliers', maxSequenceNumber);
|
||||||
}
|
}
|
||||||
|
progressBar.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncConnections(){
|
async function syncConnections(){
|
||||||
|
|
Loading…
Reference in New Issue