changes in connections

master
varun 1 year ago
parent 01a9074510
commit 66afac3f7b

@ -574,10 +574,8 @@ exports.createConnections = async (req, body) => {
capacity: data.capacity || null, capacity: data.capacity || null,
motor_status: data.motor_status || "0", motor_status: data.motor_status || "0",
motor_stop_status: data.motor_stop_status || "1" motor_stop_status: data.motor_stop_status || "1"
}], }, }],
// 'connections.outputConnections': { },
// $each: [{ outputConnections: tankname, output_type: 'overhead'}],
// },
}, },
}, },
{ new: true } { new: true }
@ -588,12 +586,27 @@ exports.createConnections = async (req, body) => {
} }
} }
return tank_connections; const response = {
tank_connections,
water_level_percentage: calculateWaterLevelPercentage(req.body.water_level, req.body.capacity)
};
reply.send({ status_code: 200, response: response});
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
function calculateWaterLevelPercentage(waterLevel, capacity) {
if (waterLevel && capacity) {
const percentage = (parseFloat(waterLevel) / parseFloat(capacity)) * 100;
return percentage.toFixed(2); // Return percentage with 2 decimal places
}
return null; // If waterLevel or capacity is missing, return null
}

Loading…
Cancel
Save