suresh 3 years ago
commit ae4e31ed9a

@ -14,8 +14,8 @@ exports.options = {
}, },
// We have to change this beacause this is running on local // We have to change this beacause this is running on local
// we have to run on this on swagger // we have to run on this on swagger
host: "localhost:3000", //Devlopemnt host on lcoal // host: "localhost:3000", //Devlopemnt host on lcoal
// host: "35.207.198.4:3000", //Production for swagger host: "35.207.198.4:3000", //Production for swagger
schemes: ["http"], schemes: ["http"],
consumes: ["application/json"], consumes: ["application/json"],
produces: ["application/json"], produces: ["application/json"],

@ -10,44 +10,24 @@ const fastify = require("fastify")({
// add new tanks // add new tanks
exports.createConnections = async (req, reply) => { exports.createConnections = async (req, body) => {
try { try {
var tankname = req.body.source;
//const username = loginObject.user.username; const tankInfo = await Tank.findOne({ tankName: tankname.toString() })
const usertobeInserted = req.body;
createConnections = { if (usertobeInserted.source) tankInfo.connections.source = usertobeInserted.source;
//userName: username, if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
source: req.body.source, if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections;
inputConnections: req.body.inputConnections, const tank_connections = await tankInfo.save();
outputConnections:req.body.outputConnections, return tank_connections;
}; } catch (err) {
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) {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
exports.updateconnectionInfo = async (req, reply) => { exports.updateconnectionInfo = async (req, reply) => {
try { try {
//const username = loginObject.user.username; //const username = loginObject.user.username;

@ -65,20 +65,14 @@ exports.updateTanksInfo = async (req, reply) => {
try { try {
//const username = loginObject.user.username; //const username = loginObject.user.username;
const tankName = req.params.tankName; 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 tank = req.body;
const { ...updateData } = tank; const { ...updateData } = tank;
const update = await Tank.findOneAndUpdate({ tankName: tankName }, updateData, { new: true }); const update = await Tank.findOneAndUpdate({ tankName: tankName }, updateData, { new: true });
if(i_tank){ //return update;
throw new Error('tankname already exists');
} reply.send({ status_code: 200, data: update });
else
{
//return update;
reply.send({ status_code: 200, data: update });
}
} }
catch (err) { catch (err) {
throw boom.boomify(err); throw boom.boomify(err);

Loading…
Cancel
Save