|
|
@ -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() })
|
|
|
|
createConnections = {
|
|
|
|
const usertobeInserted = req.body;
|
|
|
|
//userName: username,
|
|
|
|
if (usertobeInserted.source) tankInfo.connections.source = usertobeInserted.source;
|
|
|
|
source: req.body.source,
|
|
|
|
if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
|
|
|
|
inputConnections: req.body.inputConnections,
|
|
|
|
if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections;
|
|
|
|
outputConnections:req.body.outputConnections,
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
};
|
|
|
|
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;
|
|
|
|