refs #4823 Removed redundant headers
This commit is contained in:
parent
fa8eab6139
commit
ae35a0b869
60
utils.js
60
utils.js
|
@ -191,13 +191,7 @@ export async function asyncQueue(fnArray, concurrency = 1) {
|
||||||
export async function syncSuppliers(){
|
export async function syncSuppliers(){
|
||||||
let spinner = ora('Preparing to load suppliers...').start();
|
let spinner = ora('Preparing to load suppliers...').start();
|
||||||
try {
|
try {
|
||||||
let headers = {
|
const maxSequenceNumber = (await vnRequest('GET', `${env.API_URL}/organizations/current-max-sequence`)).data;
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY,
|
|
||||||
};
|
|
||||||
|
|
||||||
const maxSequenceNumber = (await vnRequest('GET', `${env.API_URL}/organizations/current-max-sequence`, null, headers)).data;
|
|
||||||
|
|
||||||
let timeFinish, timeToGoSec, timeToGoMin, timeLeft;
|
let timeFinish, timeToGoSec, timeToGoMin, timeLeft;
|
||||||
for (let curSequenceNumber = 0; curSequenceNumber <= maxSequenceNumber; curSequenceNumber++) {
|
for (let curSequenceNumber = 0; curSequenceNumber <= maxSequenceNumber; curSequenceNumber++) {
|
||||||
|
@ -245,13 +239,7 @@ export async function syncConnections(){
|
||||||
where: { isConnected: true }
|
where: { isConnected: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
let headers = {
|
const remoteConnections = (await vnRequest('GET', `${env.API_URL}/connections`)).data;
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY,
|
|
||||||
};
|
|
||||||
|
|
||||||
const remoteConnections = (await vnRequest('GET', `${env.API_URL}/connections`, null, headers)).data;
|
|
||||||
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
for (let connection of connections) {
|
for (let connection of connections) {
|
||||||
|
@ -259,7 +247,7 @@ export async function syncConnections(){
|
||||||
let remoteConnection = remoteConnections.find(remoteConnection => remoteConnection == connection.organizationId);
|
let remoteConnection = remoteConnections.find(remoteConnection => remoteConnection == connection.organizationId);
|
||||||
|
|
||||||
if (!remoteConnection)
|
if (!remoteConnection)
|
||||||
await vnRequest('PUT', `${env.API_URL}/connections/${connection.organizationId}`, null, headers);
|
await vnRequest('PUT', `${env.API_URL}/connections/${connection.organizationId}`);
|
||||||
}
|
}
|
||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -279,16 +267,11 @@ export async function syncTradeItems(){
|
||||||
});
|
});
|
||||||
let i = 1, x = 1;
|
let i = 1, x = 1;
|
||||||
for (let supplier of suppliers) {
|
for (let supplier of suppliers) {
|
||||||
let headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
supplierOrganizationId: supplier.organizationId,
|
supplierOrganizationId: supplier.organizationId,
|
||||||
}).toString();
|
}).toString();
|
||||||
let tradeItems = (await vnRequest('GET', `${env.API_URL}/trade-items?${params}`, null, headers)).data
|
let tradeItems = (await vnRequest('GET', `${env.API_URL}/trade-items?${params}`)).data
|
||||||
|
|
||||||
spinner.text = `Syncing ${i} trade items of [${x++}|${suppliers.length}] suppliers...`
|
spinner.text = `Syncing ${i} trade items of [${x++}|${suppliers.length}] suppliers...`
|
||||||
if (!tradeItems.length) continue;
|
if (!tradeItems.length) continue;
|
||||||
|
@ -311,12 +294,6 @@ export async function syncTradeItems(){
|
||||||
export async function syncSupplyLines() {
|
export async function syncSupplyLines() {
|
||||||
const spinner = ora(`Syncing supply lines...`).start();
|
const spinner = ora(`Syncing supply lines...`).start();
|
||||||
try {
|
try {
|
||||||
let headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY
|
|
||||||
};
|
|
||||||
|
|
||||||
let suppliersWithTradeItem = await models.tradeItem.findAll({
|
let suppliersWithTradeItem = await models.tradeItem.findAll({
|
||||||
attributes: ['organizationId'],
|
attributes: ['organizationId'],
|
||||||
group: ['organizationId']
|
group: ['organizationId']
|
||||||
|
@ -339,7 +316,7 @@ export async function syncSupplyLines() {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
supplierOrganizationId: supplier,
|
supplierOrganizationId: supplier,
|
||||||
}).toString();
|
}).toString();
|
||||||
let supplyLines = (await vnRequest('GET',`${env.API_URL}/supply-lines?${params}`, null, headers)).data;
|
let supplyLines = (await vnRequest('GET',`${env.API_URL}/supply-lines?${params}`)).data;
|
||||||
if (!supplyLines.length) continue
|
if (!supplyLines.length) continue
|
||||||
|
|
||||||
for (let supplyLine of supplyLines) {
|
for (let supplyLine of supplyLines) {
|
||||||
|
@ -349,7 +326,7 @@ export async function syncSupplyLines() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!tradeItem) {
|
if (!tradeItem) {
|
||||||
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items?tradeItemIds=${supplyLine.tradeItemId}`, null, headers)).data;
|
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items?tradeItemIds=${supplyLine.tradeItemId}`)).data;
|
||||||
insertItem(tradeItem[0])
|
insertItem(tradeItem[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,20 +459,14 @@ export async function insertItem(tradeItem) {
|
||||||
export async function syncWarehouses(){
|
export async function syncWarehouses(){
|
||||||
let spinner = ora('Syncing warehouses...').start();
|
let spinner = ora('Syncing warehouses...').start();
|
||||||
try {
|
try {
|
||||||
let headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY,
|
|
||||||
};
|
|
||||||
|
|
||||||
const suppliers = await models.organization.findAll({
|
const suppliers = await models.organization.findAll({
|
||||||
where: { isConnected: true }
|
where: { isConnected: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
let x = 0, i = 1;
|
let x = 0, i = 1;
|
||||||
for (let supplier of suppliers) {
|
for (let supplier of suppliers) {
|
||||||
spinner.text = `Syncing ${i} warehouses of [${x++}|${suppliers.length}]...`
|
spinner.text = `Syncing ${i} warehouses of [${x++}|${suppliers.length}] suppliers...`
|
||||||
const warehouses = (await vnRequest('GET', `${env.API_URL}/organizations/supplier/${supplier.organizationId}/warehouses`, null, headers)).data;
|
const warehouses = (await vnRequest('GET', `${env.API_URL}/organizations/supplier/${supplier.organizationId}/warehouses`)).data;
|
||||||
for (let warehouse of warehouses) {
|
for (let warehouse of warehouses) {
|
||||||
spinner.text = `Syncing ${i++} warehouses of [${x}|${suppliers.length}] suppliers...`
|
spinner.text = `Syncing ${i++} warehouses of [${x}|${suppliers.length}] suppliers...`
|
||||||
await models.warehouses.upsert({
|
await models.warehouses.upsert({
|
||||||
|
@ -525,13 +496,7 @@ export async function deleteConnections() {
|
||||||
let spinner;
|
let spinner;
|
||||||
try {
|
try {
|
||||||
let i = 1;
|
let i = 1;
|
||||||
const headers = {
|
const connectionsInFloriday = (await vnRequest('GET', `${env.API_URL}/connections`)).data;
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${await getCurrentToken()}`,
|
|
||||||
'X-Api-Key': process.env.API_KEY
|
|
||||||
};
|
|
||||||
|
|
||||||
const connectionsInFloriday = (await vnRequest('GET', `${env.API_URL}/connections`, null, headers)).data;
|
|
||||||
const connectionsInDb = await models.organization.findAll({
|
const connectionsInDb = await models.organization.findAll({
|
||||||
attributes: ['organizationId'],
|
attributes: ['organizationId'],
|
||||||
where: { isConnected: true }
|
where: { isConnected: true }
|
||||||
|
@ -573,6 +538,13 @@ export async function deleteConnections() {
|
||||||
* @return {array}
|
* @return {array}
|
||||||
**/
|
**/
|
||||||
export async function vnRequest(method, url, data, headers) {
|
export async function vnRequest(method, url, data, headers) {
|
||||||
|
if (!headers)
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${await getCurrentToken()}`,
|
||||||
|
'X-Api-Key': process.env.API_KEY,
|
||||||
|
};
|
||||||
|
|
||||||
for(let i = 0; i < env.MAX_REQUEST_RETRIES; i++) {
|
for(let i = 0; i < env.MAX_REQUEST_RETRIES; i++) {
|
||||||
try {
|
try {
|
||||||
if (['GET', 'DELETE'].includes(method))
|
if (['GET', 'DELETE'].includes(method))
|
||||||
|
|
Loading…
Reference in New Issue