changes in connections

master
varun 1 year ago
parent 950345f7dd
commit d7b7d15ec3

@ -548,32 +548,35 @@ exports.createConnections = async (req, body) => {
const tank_connections = await tankInfo.save(); 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; const connection_data = usertobeInserted.outputConnections;
console.log(connection_data, "connection_data");
for (const data of connection_data) { for (const data of connection_data) {
if (data['output_type'] === "overhead") { if (data['output_type'] === "overhead") {
const tankName = data['outputConnections']; const tankName = data['outputConnections'];
// Check if the current tank is already included in the inputConnections of any other tanks if (sump_names.includes(tankname)) {
const tanksWithCurrentTankAsInput = await Tank.find({ 'connections.inputConnections.inputConnections': tankname }); console.log(`${tankname} exists in ${sump_names}`);
} else {
// If the current tank is not in the inputConnections of any other tank, add it const tankConnections = await Tank.findOneAndUpdate(
if (tanksWithCurrentTankAsInput.length === 0) { { customerId: customerId.toString(), tankName: tankName },
// Loop through each tank to add the current tank as an inputConnection
for (const tank of tanksWithCurrentTankAsInput) {
await Tank.findOneAndUpdate(
{ customerId: customerId.toString(), tankName: tank.tankName },
{ {
$addToSet: { $addToSet: {
'connections.inputConnections': { 'connections.inputConnections': {
inputConnections: tankname, $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor || false }],
input_type: 'sump', },
inputismotor: data.outputismotor || false // 'connections.outputConnections': {
} // $each: [{ outputConnections: tankname, output_type: 'overhead'}],
} // },
},
}, },
{ new: true } { new: true }
); );
} console.log("tankConnections", tankConnections.connections.inputConnections);
console.log("tankConnections", tankConnections.connections.outputConnections);
} }
} }
} }
@ -587,7 +590,6 @@ exports.createConnections = async (req, body) => {
// exports.createConnections = async (req, body) => { // exports.createConnections = async (req, body) => {
// try { // try {
// const customerId = req.params.customerId; // const customerId = req.params.customerId;

Loading…
Cancel
Save