//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 { const customerId = req.params.customerId; var tankname = req.body.tankname; const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname }) const usertobeInserted = req.body; tankInfo.connections.source = tankInfo.tankName; 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.body.tankname const customerId = req.params.customerId; const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname }) const updateData = req.body; tankInfo.connections.source = tankInfo.tankName; 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); } }; exports.getConnections = async (req, reply) => { try { var connectionsData=await Tank.find({customerId: req.query.customerId}) // var connection_data = connectionsData.connections reply.send({ status_code: 200, data: connectionsData}); // return tank; // return tank; } catch (err) { throw boom.boomify(err); } }; exports.deleteTankConnections = async (req, reply) => { try { const customerId = req.params.customerId; const tankname = req.query.tankName; const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname }) console.log(tankInfo) tankInfo.connections.source = tankInfo.tankName; tankInfo.connections.inputConnections = []; tankInfo.connections.outputConnections = []; const tank_connections = await tankInfo.save(); return tank_connections; } catch (err) { throw boom.boomify(err); } };