|
|
@ -1,4 +1,6 @@
|
|
|
|
const Connections = require("../models/CreateConnections");
|
|
|
|
const Connections = require("../models/CreateConnections");
|
|
|
|
|
|
|
|
const Tank = require("../models/tanks");
|
|
|
|
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
const User = require("../models/User");
|
|
|
|
const boom = require("boom");
|
|
|
|
const boom = require("boom");
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
const fastify = require("fastify")({
|
|
|
@ -7,31 +9,41 @@ 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 tankInfo = await Tank.findOne({ tankName: tankname.toString() })
|
|
|
|
|
|
|
|
const updateData = req.body;
|
|
|
|
|
|
|
|
console.log(updateData.inputConnections);
|
|
|
|
|
|
|
|
if (updateData.source) tankInfo.connections.source = updateData.source;
|
|
|
|
|
|
|
|
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
|
|
|
|
|
|
|
|
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
|
|
|
|
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
return tank_connections;
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//const username = loginObject.user.username;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createConnections = {
|
|
|
|
|
|
|
|
//userName: username,
|
|
|
|
|
|
|
|
source: req.body.source,
|
|
|
|
|
|
|
|
inputConnections: req.body.inputConnections,
|
|
|
|
|
|
|
|
outputConnections:req.body.outputConnections,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateconnectionInfo = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//const username = loginObject.user.username;
|
|
|
|
|
|
|
|
const tankName = req.params.source;
|
|
|
|
|
|
|
|
const tankInfo = await Tank.findOne({ tankName: tankName.toString() })
|
|
|
|
|
|
|
|
const updateData = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (updateData.source) tankInfo.connections.source = updateData.source;
|
|
|
|
|
|
|
|
if (updateData.inputConnections) tankInfo.connections.inputConnections = updateData.inputConnections;
|
|
|
|
|
|
|
|
if (updateData.outputConnections) tankInfo.connections.outputConnections = updateData.outputConnections;
|
|
|
|
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
return tank_connections;
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|