Skip to content

Commit

Permalink
Added a route that gets all active integrations from junction table a…
Browse files Browse the repository at this point in the history
…nd the associated details, changed some redux code so only minimum required data related to integration is saved
  • Loading branch information
ydahal1 committed Mar 5, 2024
1 parent 4d62484 commit 6fd8c4f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
3 changes: 2 additions & 1 deletion client-reactjs/src/components/layout/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
52 changes: 41 additions & 11 deletions client-reactjs/src/redux/actions/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const applicationActions = {
getLicenses,
getConstraints,
updateConstraints,
getIntegrations,
updateIntegrations,
// getIntegrations,
// updateIntegrations,
getAllActiveIntegrations,
};

function applicationSelected(applicationId, applicationTitle) {
Expand Down Expand Up @@ -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 };
// }
28 changes: 27 additions & 1 deletion server/routes/integrations/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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",
Expand Down

0 comments on commit 6fd8c4f

Please sign in to comment.