From 6fd8c4f926c11aa3925ed025013d64c25ec5d07c Mon Sep 17 00:00:00 2001 From: yadhap Dahal Date: Tue, 5 Mar 2024 16:42:12 -0500 Subject: [PATCH] Added a route that gets all active integrations from junction table and the associated details, changed some redux code so only minimum required data related to integration is saved --- .../src/components/layout/Header.js | 3 +- .../src/redux/actions/Application.js | 52 +++++++++++++++---- server/routes/integrations/read.js | 28 +++++++++- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/client-reactjs/src/components/layout/Header.js b/client-reactjs/src/components/layout/Header.js index 0b237208f..7ade6f14b 100644 --- a/client-reactjs/src/components/layout/Header.js +++ b/client-reactjs/src/components/layout/Header.js @@ -143,7 +143,8 @@ class AppHeader extends Component { this.props.dispatch(applicationActions.getConsumers()); this.props.dispatch(applicationActions.getLicenses()); this.props.dispatch(applicationActions.getConstraints()); - this.props.dispatch(applicationActions.getIntegrations(this.props.application.applicationId)); + // this.props.dispatch(applicationActions.getIntegrations(this.props.application.applicationId)); + this.props.dispatch(applicationActions.getAllActiveIntegrations()); } if (this.props.newApplication) { diff --git a/client-reactjs/src/redux/actions/Application.js b/client-reactjs/src/redux/actions/Application.js index eaccbfd9b..ba653d85d 100644 --- a/client-reactjs/src/redux/actions/Application.js +++ b/client-reactjs/src/redux/actions/Application.js @@ -11,8 +11,9 @@ export const applicationActions = { getLicenses, getConstraints, updateConstraints, - getIntegrations, - updateIntegrations, + // getIntegrations, + // updateIntegrations, + getAllActiveIntegrations, }; function applicationSelected(applicationId, applicationTitle) { @@ -83,15 +84,44 @@ function updateConstraints(constraints) { return { type: Constants.UPDATE_CONSTRAINTS, constraints }; } -function getIntegrations(applicationId) { - return (dispatch) => { - fetch(`/api/integrations/get/${applicationId}`, { headers: authHeader() }) - .then((response) => (response.ok ? response.json() : handleError(response))) - .then((integrations) => dispatch({ type: Constants.INTEGRATIONS_RETRIEVED, integrations })) - .catch(console.log); +// function getIntegrations(applicationId) { +// return (dispatch) => { +// fetch(`/api/integrations/get/${applicationId}`, { headers: authHeader() }) +// .then((response) => (response.ok ? response.json() : handleError(response))) +// .then((integrations) => dispatch({ type: Constants.INTEGRATIONS_RETRIEVED, integrations })) +// .catch(console.log); +// }; +// } + +// Get all active Integrations aka integrations that are in the integrations to application mapping table +function getAllActiveIntegrations() { + return async (dispatch) => { + try { + const response = await fetch('/api/integrations/getAllActive', { headers: authHeader() }); + + if (!response.ok) { + throw handleError(response); + } + + const data = await response.json(); + const integrations = []; + if (data.length > 0) { + data.forEach((d) => { + integrations.push({ + name: d.integration.name, + integration_id: d.integration_id, + application_id: d.application_id, + }); + }); + } + + dispatch({ type: Constants.INTEGRATIONS_RETRIEVED, integrations }); + } catch (error) { + console.log(error); + } }; } -function updateIntegrations(integrations) { - return { type: Constants.UPDATE_INTEGRATIONS, integrations }; -} +// function updateIntegrations(integrations) { +// return { type: Constants.UPDATE_INTEGRATIONS, integrations }; +// } diff --git a/server/routes/integrations/read.js b/server/routes/integrations/read.js index 2eb0dc849..7841ccf41 100644 --- a/server/routes/integrations/read.js +++ b/server/routes/integrations/read.js @@ -10,8 +10,9 @@ const serverENV = path.join(process.cwd(), ".env"); const ENVPath = fs.existsSync(rootENV) ? rootENV : serverENV; const { param, body, validationResult } = require("express-validator"); require("dotenv").config({ path: ENVPath }); +const logger = require("../../config/logger"); -//return all integrations +//return all integrations active or not router.get("/getAll", async (req, res) => { try { console.log("running"); @@ -24,6 +25,31 @@ router.get("/getAll", async (req, res) => { } }); +// Get all active integrations from the integrations to application mapping table +router.get("/getAllActive/", async (req, res) => { + try { + const integrationMappingDetails = await integration_mapping.findAll( + { + include: [ + { + model: integrations, + as: "integration", + required: true, + attributes: ["name", "description", "metaData"], + }, + ], + }, + { + raw: true, + } + ); + res.status(200).send(integrationMappingDetails); + } catch (err) { + logger.error(err); + res.status(500).send("Failed to get active integrations: " + err); + } +}); + //get all integration_mappings with application_id router.get( "/getAll/:application_id",