Skip to content

Commit

Permalink
refactor(add-flow): add perma link on tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Jun 13, 2021
1 parent 3cd0a65 commit ca4e617
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/server/views/api/addFlow.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const flowHelpers = require('../helpers/flowHelpers');

async function handler(req, res) {
const {connectionName, flowHost} = req.params;
const {data} = req.body;
Expand All @@ -8,9 +10,10 @@ async function handler(req, res) {
if (!flow) return res.status(404).json({error: 'flow not found'});

try {
const result = await Flows.set(flow, data);
const flowTree = await Flows.set(flow, data);
const processedFlow = flowHelpers.processFlow(flowTree);

return res.status(200).json(result);
return res.status(200).json(processedFlow);
} catch (err) {
return res.status(500).json({error: err.message});
}
Expand Down
20 changes: 3 additions & 17 deletions src/server/views/api/getFlow.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
function processFlow(flow) {
const {job, children} = flow;
const queueName = job.queueName;

if (children && children.length > 0) {
return {
job: {...job, queueName},
children: children.map((child) => processFlow(child)),
};
} else {
return {
job: {...job, queueName},
};
}
}
const flowHelpers = require('../helpers/flowHelpers');

async function handler(req, res) {
const {connectionName, flowHost} = req.params;
Expand All @@ -27,8 +13,8 @@ async function handler(req, res) {
depth: Number(depth),
maxChildren: Number(maxChildren),
});
const processedFlow = processFlow(flowTree);
const {job} = flowTree;
const processedFlow = flowHelpers.processFlow(flowTree);

return res.status(200).json(processedFlow);
} catch (err) {
return res.status(500).json({error: err.message});
Expand Down
19 changes: 19 additions & 0 deletions src/server/views/helpers/flowHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Helpers = {
processFlow: function (flow) {
const {job, children} = flow;
const queueName = job.queueName;

if (children && children.length > 0) {
return {
job: {...job, queueName},
children: children.map((child) => this.processFlow(child)),
};
} else {
return {
job: {...job, queueName},
};
}
},
};

module.exports = Helpers;

0 comments on commit ca4e617

Please sign in to comment.