|
|
|
const Connections = require("../models/CreateConnections");
|
|
|
|
const Tank = require("../models/tanks");
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
const boom = require("boom");
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
logger: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// add new tanks
|
|
|
|
|
|
|
|
exports.createConnections = async (req, body) => {
|
|
|
|
try {
|
|
|
|
var tankname = req.body.source;
|
|
|
|
|
|
|
|
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;
|
|
|
|
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) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|