|
|
|
@ -520,46 +520,23 @@ exports.createConnections = async (req, body) => {
|
|
|
|
|
return {
|
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
|
input_type: connection.input_type,
|
|
|
|
|
inputismotor: connection.inputismotor || false,
|
|
|
|
|
motor_id: connection.motor_id || null,
|
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
|
motor_stop_status: connection.motor_stop_status || "1",
|
|
|
|
|
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
|
|
|
|
|
water_level: connection.water_level || null,
|
|
|
|
|
capacity: connection.capacity || null,
|
|
|
|
|
water_level: connection.water_level || null
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (usertobeInserted.outputConnections) {
|
|
|
|
|
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
|
|
|
|
|
motor_stop_status: connection.motor_stop_status || "1"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
|
|
const connection_data_check = tank_connections.connections.inputConnections;
|
|
|
|
|
const sump_names = connection_data_check.map(d => d.inputConnections);
|
|
|
|
|
console.log(sump_names);
|
|
|
|
|
|
|
|
|
|
const connection_data = usertobeInserted.outputConnections;
|
|
|
|
|
console.log(connection_data, "connection_data");
|
|
|
|
|
for (const data of connection_data) {
|
|
|
|
|
if (data['output_type'] === "overhead") {
|
|
|
|
|
const tankName = data['outputConnections'];
|
|
|
|
|
if (usertobeInserted.outputConnections) {
|
|
|
|
|
const connection_data = usertobeInserted.outputConnections;
|
|
|
|
|
console.log(connection_data, "connection_data");
|
|
|
|
|
for (const data of connection_data) {
|
|
|
|
|
if (data['output_type'] === "overhead") {
|
|
|
|
|
const tankName = data['outputConnections'];
|
|
|
|
|
|
|
|
|
|
if (sump_names.includes(tankname)) {
|
|
|
|
|
console.log(`${tankname} exists in ${sump_names}`);
|
|
|
|
|
} else {
|
|
|
|
|
const tankConnections = await Tank.findOneAndUpdate(
|
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
|
{
|
|
|
|
@ -568,12 +545,12 @@ exports.createConnections = async (req, body) => {
|
|
|
|
|
$each: [{
|
|
|
|
|
inputConnections: tankname,
|
|
|
|
|
input_type: 'sump',
|
|
|
|
|
inputismotor: usertobeInserted.outputismotor || false,
|
|
|
|
|
motor_id: usertobeInserted.motor_id || null,
|
|
|
|
|
water_level: usertobeInserted.water_level || null,
|
|
|
|
|
capacity: usertobeInserted.capacity || null,
|
|
|
|
|
motor_status: usertobeInserted.motor_status || "0",
|
|
|
|
|
motor_stop_status: usertobeInserted.motor_stop_status || "1"
|
|
|
|
|
inputismotor: data.outputismotor || false,
|
|
|
|
|
motor_id: data.motor_id || null,
|
|
|
|
|
water_level: req.body.water_level || null,
|
|
|
|
|
capacity: req.body.capacity || null,
|
|
|
|
|
motor_status: req.body.motor_status || "0",
|
|
|
|
|
motor_stop_status: req.body.motor_stop_status || "1"
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@ -585,26 +562,11 @@ exports.createConnections = async (req, body) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|