ashok 1 year ago
commit 5faffd5209

@ -1433,6 +1433,7 @@ exports.calculateCapacity = async (req, reply) => {
// }; // };
exports.IotDevice = async (req, reply) => { exports.IotDevice = async (req, reply) => {
try { try {
const { hardwareId, mode, tanks } = req.body; const { hardwareId, mode, tanks } = req.body;
@ -1488,23 +1489,26 @@ exports.IotDevice = async (req, reply) => {
const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10); const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10);
const water_level = water_level_height * waterCapacityPerCm; const water_level = water_level_height * waterCapacityPerCm;
existingTank.waterlevel = water_level; if (water_level >= 0) {
existingTank.waterlevel = water_level;
// Save the updated tank document // Save the updated tank document
await existingTank.save(); await existingTank.save();
// Update linked tanks // Update linked tanks
for (const outputConnection of existingTank.connections.outputConnections) { for (const outputConnection of existingTank.connections.outputConnections) {
const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type }); const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type });
if (linkedTank) { if (linkedTank) {
for (const inputConnection of linkedTank.connections.inputConnections) { for (const inputConnection of linkedTank.connections.inputConnections) {
if (inputConnection.inputConnections === tank_name) { if (inputConnection.inputConnections === tank_name) {
inputConnection.water_level = water_level; inputConnection.water_level = water_level;
await linkedTank.save(); await linkedTank.save();
}
} }
} }
} }
} }
} }
// Send the latest three documents // Send the latest three documents
@ -1525,6 +1529,7 @@ exports.IotDevice = async (req, reply) => {
// exports.IotDevice3 = async (req, reply) => { // exports.IotDevice3 = async (req, reply) => {
// try { // try {
// const { hardwareId, mode, tanks } = req.body; // const { hardwareId, mode, tanks } = req.body;

Loading…
Cancel
Save