refs #4823 Fix on axios.put
This commit is contained in:
parent
1a746968b8
commit
4a264cf147
20
utils.js
20
utils.js
|
@ -20,11 +20,13 @@ export async function requestToken() {
|
||||||
|
|
||||||
const clientConfigData = await models.clientConfig.findOne();
|
const clientConfigData = await models.clientConfig.findOne();
|
||||||
|
|
||||||
let tokenExpirationDate;
|
let tokenExpirationDate, token;
|
||||||
if (clientConfigData)
|
if (clientConfigData) {
|
||||||
|
token = clientConfigData.currentToken;
|
||||||
tokenExpirationDate = clientConfigData.tokenExpiration;
|
tokenExpirationDate = clientConfigData.tokenExpiration;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tokenExpirationDate || moment().isAfter(tokenExpirationDate)) {
|
if (!token || !tokenExpirationDate || moment().isAfter(tokenExpirationDate)) {
|
||||||
let clientId, clientSecret
|
let clientId, clientSecret
|
||||||
if (JSON.parse(env.USE_SECRETS_DB)) {
|
if (JSON.parse(env.USE_SECRETS_DB)) {
|
||||||
clientId = clientConfigData.clientId;
|
clientId = clientConfigData.clientId;
|
||||||
|
@ -343,7 +345,7 @@ export async function syncConn(){
|
||||||
'X-Api-Key': process.env.API_KEY
|
'X-Api-Key': process.env.API_KEY
|
||||||
};
|
};
|
||||||
|
|
||||||
let remoteConnections = await axios.get(`${env.API_URL}/connections`, { headers });
|
const remoteConnections = await axios.get(`${env.API_URL}/connections`, { headers });
|
||||||
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
for (let connection of connections){
|
for (let connection of connections){
|
||||||
|
@ -352,10 +354,10 @@ export async function syncConn(){
|
||||||
continue;
|
continue;
|
||||||
let remoteConnection = remoteConnections.data.find(remoteConnection => remoteConnection == connection.supplierOrganizationId);
|
let remoteConnection = remoteConnections.data.find(remoteConnection => remoteConnection == connection.supplierOrganizationId);
|
||||||
|
|
||||||
if (remoteConnection == undefined){
|
if (!remoteConnection){
|
||||||
console.log('Connection: ', connection, 'does not exist in the remote server');
|
console.log('Connection: ', connection.supplierOrganizationId, 'does not exist in the remote server');
|
||||||
console.log('Creating remote connection');
|
console.log('Creating remote connection');
|
||||||
await axios.put(`${env.API_URL}/connections/${connection.supplierOrganizationId}`, { headers });
|
await axios.put(`${env.API_URL}/connections/${connection.supplierOrganizationId}`, null, { headers });
|
||||||
await models.connection.update({ isConnected: true }, {
|
await models.connection.update({ isConnected: true }, {
|
||||||
where: {
|
where: {
|
||||||
supplierOrganizationId: connection.supplierOrganizationId
|
supplierOrganizationId: connection.supplierOrganizationId
|
||||||
|
@ -474,8 +476,8 @@ export async function syncSupplyLines(){
|
||||||
resolve(supplyLines);
|
resolve(supplyLines);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error while syncing supply lines for: ', supplier.commercialName, ' - ' , tradeItem.name);
|
if (err.message = 'Request failed with status code 429')
|
||||||
console.log(err);
|
console.log('Request failed with status code 429 - Too many request');
|
||||||
resolve([]);
|
resolve([]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue