diff --git a/src/config/swagger.js b/src/config/swagger.js index adf1ae84..7308e53c 100644 --- a/src/config/swagger.js +++ b/src/config/swagger.js @@ -14,8 +14,8 @@ exports.options = { }, // We have to change this beacause this is running on local // we have to run on this on swagger - host: "localhost:3000", //Devlopemnt host on lcoal - // host: "35.207.198.4:3000", //Production for swagger + // host: "localhost:3000", //Devlopemnt host on lcoal + host: "35.207.198.4:3000", //Production for swagger schemes: ["http"], consumes: ["application/json"], produces: ["application/json"], diff --git a/src/controllers/createConnectionController.js b/src/controllers/createConnectionController.js index 22a79a6c..f3e6fc80 100644 --- a/src/controllers/createConnectionController.js +++ b/src/controllers/createConnectionController.js @@ -10,44 +10,24 @@ const fastify = require("fastify")({ // add new tanks -exports.createConnections = async (req, reply) => { +exports.createConnections = async (req, body) => { try { - - //const username = loginObject.user.username; - - createConnections = { - //userName: username, - source: req.body.source, - inputConnections: req.body.inputConnections, - outputConnections:req.body.outputConnections, - }; - - - - var tank_name = req.body.source - var i_tank = await Tank.findOne({ tankName: tank_name}) - if(i_tank){ - throw new Error('tankname already exists'); - } - else { - var connections = new Connections(createConnections); - checkFormEncoding = isUserFormUrlEncoded(req); - if (checkFormEncoding.isUserFormUrlEncoded) { - usertobeInserted = checkFormEncoding.connections; - connections.source = usertobeInserted.source; - connections.inputConnections = req.body.inputConnections; - connections.outputConnections = req.body.outputConnections; - } - const insertedConnection = await connections.save(); - return insertedConnection; - } - } - catch (err) { + var tankname = req.body.source; + + const tankInfo = await Tank.findOne({ tankName: tankname.toString() }) + const usertobeInserted = req.body; + if (usertobeInserted.source) tankInfo.connections.source = usertobeInserted.source; + if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections; + if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections; + const tank_connections = await tankInfo.save(); + return tank_connections; + } catch (err) { throw boom.boomify(err); } }; + exports.updateconnectionInfo = async (req, reply) => { try { //const username = loginObject.user.username; diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index ecc2ff88..3c70347a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -65,20 +65,14 @@ exports.updateTanksInfo = async (req, reply) => { try { //const username = loginObject.user.username; const tankName = req.params.tankName; - - var tank_name = req.body.tankName - var i_tank = await Tank.findOne({ tankName: tank_name}) const tank = req.body; const { ...updateData } = tank; const update = await Tank.findOneAndUpdate({ tankName: tankName }, updateData, { new: true }); - if(i_tank){ - throw new Error('tankname already exists'); - } - else - { - //return update; - reply.send({ status_code: 200, data: update }); - } + //return update; + + reply.send({ status_code: 200, data: update }); + + } catch (err) { throw boom.boomify(err);