diff --git a/src/controllers/createConnectionController.js b/src/controllers/createConnectionController.js index 16d7ced2..58230682 100644 --- a/src/controllers/createConnectionController.js +++ b/src/controllers/createConnectionController.js @@ -534,13 +534,13 @@ exports.createConnections = async (req, body) => { tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => { return { outputConnections: connection.outputConnections, - output_type: connection.output_type, - motor_id: connection.motor_id || null, - motor_status: connection.motor_status || "0", - motor_stop_status: connection.motor_stop_status || "1", - outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false, - capacity: connection.capacity || null, - water_level: connection.water_level || null + output_type: connection.output_type, + motor_id: connection.motor_id || null, + motor_status: connection.motor_status || "0", + motor_stop_status: connection.motor_stop_status || "1", + outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false, + capacity: connection.capacity || null, + water_level: connection.water_level || null }; }); } @@ -574,10 +574,8 @@ exports.createConnections = async (req, body) => { capacity: data.capacity || null, motor_status: data.motor_status || "0", motor_stop_status: data.motor_stop_status || "1" - }], }, - // 'connections.outputConnections': { - // $each: [{ outputConnections: tankname, output_type: 'overhead'}], - // }, + }], + }, }, }, { 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) { 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 +} + +