refs #4823 Changes
This commit is contained in:
parent
c57916815d
commit
38c0a46614
|
@ -1,9 +1,15 @@
|
|||
import { Sequelize } from 'sequelize';
|
||||
|
||||
const suppliers = {
|
||||
isConnected: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
sequenceNumber: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
companyGln: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
commercialName: {
|
||||
type: Sequelize.STRING,
|
||||
|
@ -18,6 +24,19 @@ const suppliers = {
|
|||
website: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
organizationId: {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
rfhRelationId: {
|
||||
type: Sequelize.INTEGER,
|
||||
},
|
||||
paymentProviders: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
endDate: {
|
||||
type: Sequelize.DATE,
|
||||
},
|
||||
mailingAddress: {
|
||||
type: Sequelize.JSON,
|
||||
},
|
||||
|
@ -27,31 +46,12 @@ const suppliers = {
|
|||
pythosanitaryNumber: {
|
||||
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: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
paymentProviders: {
|
||||
type: Sequelize.STRING,
|
||||
isConnected: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
"name": "floriday",
|
||||
"module": "index.ts",
|
||||
"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": {
|
||||
"cli-progress": "^3.11.2",
|
||||
"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 { v4 as uuidv4 } from 'uuid';
|
||||
import colors from 'colors';
|
||||
//import cliProgress from 'cli-progress';
|
||||
import cliProgress from 'cli-progress';
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ async function getClientToken() {
|
|||
const clientConfigData = await models.clientConfig.findAll();
|
||||
|
||||
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 tokenExpirationDate = clientConfigData[0].tokenExpiration;
|
||||
|
@ -171,10 +171,10 @@ async function asyncQueue(fnArray, concurrency = 1) {
|
|||
async function syncSequence(current = 0, model = null ,maximumSequenceNumber = 0){
|
||||
if (model == null && current == 0){
|
||||
|
||||
let mockModels = ['suppliers','tradeItems','supplyLines',];
|
||||
let mockModels = ['suppliers','tradeItems','supplyLines'];
|
||||
|
||||
for (let i = 0; i < mockModels.length; i++) {
|
||||
const element = mockModels[i];
|
||||
for (let model in mockModels) {
|
||||
const element = mockModels[model];
|
||||
console.log('Syncing sequence for: ', element);
|
||||
await syncSequence(0, element);
|
||||
}
|
||||
|
@ -219,25 +219,27 @@ async function syncSequence(current = 0, model = null ,maximumSequenceNumber = 0
|
|||
}
|
||||
|
||||
async function syncSuppliers(){
|
||||
|
||||
let headers = {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${await getJWT()}`,
|
||||
'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',
|
||||
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, {
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
|
@ -246,31 +248,33 @@ async function syncSuppliers(){
|
|||
let data = await response.json();
|
||||
|
||||
let suppliers = data.results;
|
||||
|
||||
for (let supplier of suppliers) {
|
||||
i = supplier.sequenceNumber;
|
||||
curSequenceNumber = supplier.sequenceNumber;
|
||||
if (!progressBar.value) {
|
||||
progressBar.start(maxSequenceNumber, curSequenceNumber);
|
||||
}
|
||||
await models.supplier.upsert({
|
||||
isConnected: false,
|
||||
sequenceNumber: supplier.sequenceNumber,
|
||||
companyGln: supplier.companyGln,
|
||||
name: supplier.name,
|
||||
commercialName: supplier.commercialName,
|
||||
email: supplier.email,
|
||||
phone: supplier.phone,
|
||||
website: supplier.website,
|
||||
organizationId: supplier.organizationId,
|
||||
rfhRelationId: supplier.rfhRelationId,
|
||||
paymentProviders: `${supplier.paymentProviders}`,
|
||||
endDate: supplier.endDate,
|
||||
mailingAddress: supplier.mailingAddress,
|
||||
physicalAddress: supplier.physicalAddress,
|
||||
pythosanitaryNumber: supplier.pythosanitaryNumber,
|
||||
sequenceNumber: supplier.sequenceNumber,
|
||||
organizationId: supplier.organizationId,
|
||||
companyGln: supplier.companyGln,
|
||||
name: supplier.name,
|
||||
endDate: supplier.endDate,
|
||||
rfhRelationId: supplier.rfhRelationId,
|
||||
organizationType: supplier.organizationType,
|
||||
paymentProviders: `${supplier.paymentProviders}`,
|
||||
organizationType: supplier.organizationType
|
||||
});
|
||||
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(){
|
||||
|
|
Loading…
Reference in New Issue