ashok 1 year ago
commit a4f20a07ec

@ -510,7 +510,11 @@ exports.createConnections = async (req, body) => {
try {
const customerId = req.params.customerId;
const tankname = req.body.tankname;
const water_capacity = req.body.capacity;
const water_water_level = req.body.water_level
const motorId = req.body.motor_id
const motorStatus = req.body.motor_status
const motorStopStatus = req.body.motor_stop_status
const tankInfo = await Tank.findOne({ customerId: customerId.toString(), tankName: tankname });
const usertobeInserted = req.body;
tankInfo.connections.source = tankInfo.tankName;
@ -520,23 +524,46 @@ exports.createConnections = async (req, body) => {
return {
inputConnections: connection.inputConnections,
input_type: connection.input_type,
inputismotor: connection.inputismotor || false,
motor_id: connection.motor_id || null,
water_level: connection.water_level || null,
capacity: connection.capacity || null,
motor_status: connection.motor_status || "0",
motor_stop_status: connection.motor_stop_status || "1"
motor_stop_status: connection.motor_stop_status || "1",
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
capacity: connection.capacity || null,
water_level: connection.water_level || null
};
});
}
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'];
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
};
});
}
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 (sump_names.includes(tankname)) {
console.log(`${tankname} exists in ${sump_names}`);
} else {
const tankConnections = await Tank.findOneAndUpdate(
{ customerId: customerId.toString(), tankName: tankName },
{
@ -545,12 +572,12 @@ exports.createConnections = async (req, body) => {
$each: [{
inputConnections: tankname,
input_type: 'sump',
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"
inputismotor: true || false,
motor_id: motorId || null,
water_level: water_water_level || null,
capacity: water_capacity || null,
motor_status: motorStatus || "0",
motor_stop_status: motorStopStatus || "1"
}],
},
},
@ -562,6 +589,9 @@ exports.createConnections = async (req, body) => {
}
}
}
} catch (err) {
throw boom.boomify(err);
}

Loading…
Cancel
Save