diff --git a/backend/src/controllers/cypherController.js b/backend/src/controllers/cypherController.js index b6f9c6bf..72db6606 100644 --- a/backend/src/controllers/cypherController.js +++ b/backend/src/controllers/cypherController.js @@ -41,12 +41,11 @@ class CypherController { let [client, transaction] = await db.graphRepository.createTransaction(); try { let graph = new GraphCreator({ - nodes: req.files.nodes, - edges: req.files.edges, + nodefiles: req.files.nodes, + edgefiles: req.files.edges, graphName: req.body.graphName, dropGraph: req.body.dropGraph === 'true' }); - await graph.parseData(); const DROP = graph.query.graph.drop; const CREATE = graph.query.graph.create; diff --git a/backend/src/models/GraphCreator.js b/backend/src/models/GraphCreator.js index 41c81f39..b44f9ba9 100644 --- a/backend/src/models/GraphCreator.js +++ b/backend/src/models/GraphCreator.js @@ -3,9 +3,9 @@ const { getDelete, toAgeProps } = require('../util/ObjectExtras'); const QueryBuilder = require('./QueryBuilder'); class GraphCreator { - constructor({nodes, edges, graphName, dropGraph}={}){ - this.nodefiles = nodes; - this.edgefiles = edges; + constructor({nodefiles=[], edgefiles=[], graphName, dropGraph}={}){ + this.nodefiles = nodefiles; + this.edgefiles = edgefiles; this.dropGraph = dropGraph; this.graphName = graphName; this.nodes = []; @@ -92,26 +92,30 @@ class GraphCreator { } async parseData(){ this.createGraph(this.dropGraph); - - this.nodes = await Promise.all(this.nodefiles.map((node) => new Promise((resolve) => { - this.createNodeLabel(node.originalname); - this.readData(node.buffer.toString('utf8'), node.originalname, resolve); - }))); - this.nodes.forEach((nodeFile)=>{ - nodeFile.data.forEach((n)=>{ - this.createNode(n, nodeFile.type); + if(this.nodefiles.length > 0){ + this.nodes = await Promise.all(this.nodefiles.map((node) => new Promise((resolve) => { + this.createNodeLabel(node.originalname); + this.readData(node.buffer.toString('utf8'), node.originalname, resolve); + }))); + this.nodes.forEach((nodeFile)=>{ + nodeFile.data.forEach((n)=>{ + this.createNode(n, nodeFile.type); + }); }); - }); - this.edges = await Promise.all(this.edgefiles.map((edge) => new Promise((resolve) => { - this.createEdgeLabel(edge.originalname); - this.readData(edge.buffer.toString('utf8'), edge.originalname, resolve); - }))); + if (this.edgefiles.length > 0){ + this.edges = await Promise.all(this.edgefiles.map((edge) => new Promise((resolve) => { + this.createEdgeLabel(edge.originalname); + this.readData(edge.buffer.toString('utf8'), edge.originalname, resolve); + }))); + + this.edges.forEach((edgeFile)=>{ + edgeFile.data.forEach((e)=>{ + this.createEdge(e, edgeFile.type); + }); + }); + } + } - this.edges.forEach((edgeFile)=>{ - edgeFile.data.forEach((e)=>{ - this.createEdge(e, edgeFile.type); - }); - }); return this.query; }