diff --git a/package.json b/package.json index dfccd7c6..6f020484 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "climate-warehouse", - "version": "0.0.27", + "version": "0.0.28", "private": true, "bin": "build/server.js", "type": "module", diff --git a/src/models/governance/governance.model.js b/src/models/governance/governance.model.js index 4eafe877..4a4dc518 100644 --- a/src/models/governance/governance.model.js +++ b/src/models/governance/governance.model.js @@ -32,35 +32,41 @@ class Governance extends Model { } static async sync() { - if (!GOVERANCE_BODY_ID || !GOVERNANCE_BODY_IP || !GOVERNANCE_BODY_PORT) { - throw new Error('Missing information in env to sync Governance data'); - } + try { + if (!GOVERANCE_BODY_ID || !GOVERNANCE_BODY_IP || !GOVERNANCE_BODY_PORT) { + throw new Error('Missing information in env to sync Governance data'); + } + + const governanceData = await datalayer.getSubscribedStoreData( + GOVERANCE_BODY_ID, + GOVERNANCE_BODY_IP, + GOVERNANCE_BODY_PORT, + ); - const governanceData = await datalayer.getSubscribedStoreData( - GOVERANCE_BODY_ID, - GOVERNANCE_BODY_IP, - GOVERNANCE_BODY_PORT, - ); + const updates = []; - const updates = []; + if (governanceData.orgList) { + updates.push({ + metaKey: 'orgList', + metaValue: governanceData.orgList, + confirmed: true, + }); + } - if (governanceData.orgList) { - updates.push({ - metaKey: 'orgList', - metaValue: governanceData.orgList, - confirmed: true, - }); - } + if (governanceData.pickList) { + updates.push({ + metaKey: 'pickList', + metaValue: governanceData.pickList, + confirmed: true, + }); + } - if (governanceData.pickList) { - updates.push({ - metaKey: 'pickList', - metaValue: governanceData.pickList, - confirmed: true, - }); + await Promise.all( + updates.map(async (update) => Governance.upsert(update)), + ); + } catch (error) { + console.log(error.message); } - - await Promise.all(updates.map(async (update) => Governance.upsert(update))); } static async updateGoveranceBodyData(keyValueArray) {