From 559bb6e12cf4fd3a4f2428b5080e4886c11b89e4 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 7 Feb 2023 07:50:05 +0100 Subject: [PATCH] fix multiple config lines --- models/index.js | 11 ++++++++--- suppliersGln.js | 2 ++ utils.js | 20 +++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/models/index.js b/models/index.js index e9b3142..32ce29b 100644 --- a/models/index.js +++ b/models/index.js @@ -149,9 +149,14 @@ if (process.env.FORCE_SYNC == true) { } if (process.env.SECRETS) { - await models.clientConfig.create({ - clientId: process.env.CLIENT_ID, - clientSecret: process.env.CLIENT_SECRET, + await models.clientConfig.findOrCreate({ + where: { + id: 1, + }, + defaults: { + clientId: process.env.CLIENT_ID, + clientSecret: process.env.CLIENT_SECRET, + }, }); } diff --git a/suppliersGln.js b/suppliersGln.js index 0692031..4ba939c 100644 --- a/suppliersGln.js +++ b/suppliersGln.js @@ -6,4 +6,6 @@ let floraholland = [ 8718288004970, ]; +let others = []; + export default {floraholland}; \ No newline at end of file diff --git a/utils.js b/utils.js index 520e93c..9f01908 100644 --- a/utils.js +++ b/utils.js @@ -81,20 +81,18 @@ async function getClientToken() { async function updateClientConfig(clientId, clientSecret, accessToken, tokenExpirationDate) { try { console.log('Updating the client config with the new token...'); - await models.clientConfig.update( - { + await models.clientConfig.findOrCreate({ + where: { + id: 1, + }, + defaults: { clientId: clientId, clientSecret: clientSecret, currentToken: accessToken, tokenExpiration: tokenExpirationDate, - requestLimit : 500 + requestLimit: 500, }, - { - where: { - id: 1, - }, - } - ); + }); console.log('Client config updated, new Token set'); console.log('New token expiration date: ', tokenExpirationDate); } catch (error) { @@ -397,9 +395,9 @@ async function syncTradeItems(){ headers: headers }); - let data = await request.json(); + let itemdata = await request.json(); - let results = data.results; + let results = itemdata.results; if (results.length == 0) { console.log('No more trade items to sync');