You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
//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.findOne({customerId: req.query.customerId})
|
|
var connection_data = connectionsData.connections
|
|
|
|
reply.send({ status_code: 200, data: connection_data});
|
|
// return tank;
|
|
|
|
|
|
// return tank;
|
|
} catch (err) {
|
|
throw boom.boomify(err);
|
|
}
|
|
};
|
|
|
|
|
|
|