|
|
@ -451,82 +451,6 @@ const fastify = require("fastify")({
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
exports.createConnections = async (req, body) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
const tankname = req.body.tankname;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tankInfo = await Tank.findOne({ customerId: customerId.toString(), tankName: tankname });
|
|
|
|
|
|
|
|
const usertobeInserted = req.body;
|
|
|
|
|
|
|
|
tankInfo.connections.source = tankInfo.tankName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (usertobeInserted.inputConnections) {
|
|
|
|
|
|
|
|
tankInfo.connections.inputConnections = usertobeInserted.inputConnections.map(connection => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
|
|
|
|
input_type: connection.input_type,
|
|
|
|
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
|
|
|
|
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
|
|
|
|
|
|
|
|
motor_id: connection.motor_id || null,
|
|
|
|
|
|
|
|
motor_stop_status: connection.motor_stop_status || "1"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
output_type: connection.output_type,
|
|
|
|
|
|
|
|
outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
|
|
|
|
|
|
|
|
motor_id: connection.motor_id || 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 (sump_names.includes(tankname)) {
|
|
|
|
|
|
|
|
console.log(`${tankname} exists in ${sump_names}`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const tankConnections = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$addToSet: {
|
|
|
|
|
|
|
|
'connections.inputConnections': {
|
|
|
|
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor || false }],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
'connections.outputConnections': {
|
|
|
|
|
|
|
|
$each: [{ outputConnections: tankname, output_type: 'overhead', motor_id: data.motor_id || null, motor_stop_status: "1"}],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ new: true }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log("tankConnections", tankConnections.connections.inputConnections);
|
|
|
|
|
|
|
|
console.log("tankConnections", tankConnections.connections.outputConnections);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tank_connections;
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createConnections = async (req, body) => {
|
|
|
|
exports.createConnections = async (req, body) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -542,10 +466,8 @@ exports.createConnections = async (req, body) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
motor_status: connection.motor_status || "1",
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
|
|
|
|
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
|
|
|
|
motor_id: connection.motor_id || null,
|
|
|
|
|
|
|
|
motor_stop_status: connection.motor_stop_status || "1"
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -556,9 +478,6 @@ exports.createConnections = async (req, body) => {
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
|
|
|
|
outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
|
|
|
|
motor_id: connection.motor_id || null,
|
|
|
|
|
|
|
|
motor_status: connection.motor_status || "1",
|
|
|
|
|
|
|
|
motor_stop_status: connection.motor_stop_status || "1"
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -585,9 +504,9 @@ exports.createConnections = async (req, body) => {
|
|
|
|
'connections.inputConnections': {
|
|
|
|
'connections.inputConnections': {
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor || false }],
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor || false }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'connections.outputConnections': {
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
$each: [{ outputConnections: tankname, output_type: 'overhead', motor_id: data.motor_id || null, motor_stop_status: "1"}],
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead'}],
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ new: true }
|
|
|
|
{ new: true }
|
|
|
@ -606,7 +525,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;
|
|
|
@ -848,4 +766,3 @@ exports.getConnections = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|