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 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"],

@ -10,44 +10,24 @@ const fastify = require("fastify")({
// add new tanks
exports.createConnections = async (req, reply) => {
exports.createConnections = async (req, body) => {
try {
var tankname = req.body.source;
//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) {
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;

@ -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);

Loading…
Cancel
Save