add changes in tankcontroller and creeate connection

master
suresh 3 years ago
parent 45e48c594c
commit b288242079

@ -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,25 +10,44 @@ const fastify = require("fastify")({
// add new tanks // add new tanks
exports.createConnections = async (req, body) => { exports.createConnections = async (req, reply) => {
try { try {
var tankname = req.body.source;
const tankInfo = await Tank.findOne({ tankName: tankname.toString() }) //const username = loginObject.user.username;
const updateData = req.body;
console.log(updateData.inputConnections); createConnections = {
if (updateData.source) tankInfo.connections.source = updateData.source; //userName: username,
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections; source: req.body.source,
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.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,14 +65,20 @@ 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){
throw new Error('tankname already exists');
}
else
{
//return update; //return update;
reply.send({ status_code: 200, data: update }); reply.send({ status_code: 200, data: update });
}
} }
catch (err) { catch (err) {
throw boom.boomify(err); throw boom.boomify(err);

Loading…
Cancel
Save