|
|
@ -12,81 +12,577 @@ const fastify = require("fastify")({
|
|
|
|
|
|
|
|
|
|
|
|
// add new tanks
|
|
|
|
// add new tanks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
|
|
// // update inputismotor field for each input connection
|
|
|
|
|
|
|
|
// tankInfo.connections.inputConnections = usertobeInserted.inputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// inputConnections: connection.inputConnections,
|
|
|
|
|
|
|
|
// input_type: connection.input_type,
|
|
|
|
|
|
|
|
// motor_status: connection.motor_status || "0",
|
|
|
|
|
|
|
|
// inputismotor: connection.inputismotor || false // default to false if not specified
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// // update outputismotor field for each output connection
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor || false // default to false if not specified
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const connection_data = req.body.outputConnections
|
|
|
|
|
|
|
|
// for (const data of connection_data){
|
|
|
|
|
|
|
|
// if(data['output_type'] === "overhead"){
|
|
|
|
|
|
|
|
// const tankName = data['outputConnections']
|
|
|
|
|
|
|
|
// const tank_info = await Tank.findOne({ customerId: customerId.toString(),tankName:tankName })
|
|
|
|
|
|
|
|
// const connection_data_check =tank_info.connections.inputConnections
|
|
|
|
|
|
|
|
// const sump_names=[]
|
|
|
|
|
|
|
|
// for(const d of connection_data_check){
|
|
|
|
|
|
|
|
// if (sump_names.includes(d.inputConnections)) {
|
|
|
|
|
|
|
|
// console.log(`${d.inputConnections} exists in ${sump_names}`);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// sump_names.push(d.inputConnections)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// console.log(sump_names)
|
|
|
|
|
|
|
|
// //tank_info.connections.inputConnections = tankname.toString()
|
|
|
|
|
|
|
|
// 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' }] } } },
|
|
|
|
|
|
|
|
// { new: true }
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //console.log(tankConnections)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return tank_connections;
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// 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.inputismotor || false,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor || false,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 = tank_connections.connections.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: false }] } } },
|
|
|
|
|
|
|
|
// { new: true }
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// console.log("tankConnections", tankConnections.connections.);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return tank_connections;
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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.inputismotor ,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor ,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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: usertobeInserted.inputismotor }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor: usertobeInserted.outputismotor }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// { 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) => {
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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: false }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor: false }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// { 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) => {
|
|
|
|
|
|
|
|
// 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.inputismotor,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor ,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const outputConnectionNames = usertobeInserted.outputConnections.map(connection => connection.outputConnections);
|
|
|
|
|
|
|
|
// const existingInputConnections = tankInfo.connections.inputConnections.filter(connection =>
|
|
|
|
|
|
|
|
// outputConnectionNames.includes(connection.inputConnections)
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for (const connection of existingInputConnections) {
|
|
|
|
|
|
|
|
// connection.inputismotor = true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
// console.log("tank_connections", tank_connections.connections.inputConnections)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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'];
|
|
|
|
|
|
|
|
// console.log("tankName", tankName)
|
|
|
|
|
|
|
|
// 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: tank_connections.connections.inputConnections.inputismotor }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor:tank_connections.connections.outputConnections.outputismotor }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// { 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 {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const tankname = req.body.tankname;
|
|
|
|
const tankname = req.body.tankname;
|
|
|
|
|
|
|
|
|
|
|
|
const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname })
|
|
|
|
const tankInfo = await Tank.findOne({ customerId: customerId.toString(), tankName: tankname });
|
|
|
|
const usertobeInserted = req.body;
|
|
|
|
const usertobeInserted = req.body;
|
|
|
|
tankInfo.connections.source = tankInfo.tankName;
|
|
|
|
tankInfo.connections.source = tankInfo.tankName;
|
|
|
|
|
|
|
|
|
|
|
|
if (usertobeInserted.inputConnections) {
|
|
|
|
if (usertobeInserted.inputConnections) {
|
|
|
|
// update inputismotor field for each input connection
|
|
|
|
|
|
|
|
tankInfo.connections.inputConnections = usertobeInserted.inputConnections.map(connection => {
|
|
|
|
tankInfo.connections.inputConnections = usertobeInserted.inputConnections.map(connection => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
motor_status: "0",
|
|
|
|
inputismotor: connection.inputismotor // default to false if not specified
|
|
|
|
inputismotor: connection.inputismotor,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (usertobeInserted.outputConnections) {
|
|
|
|
if (usertobeInserted.outputConnections) {
|
|
|
|
// update outputismotor field for each output connection
|
|
|
|
|
|
|
|
tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
outputismotor: connection.outputismotor // default to false if not specified
|
|
|
|
motor_status: "0",
|
|
|
|
|
|
|
|
outputismotor: connection.outputismotor
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const connection_data = req.body.outputConnections
|
|
|
|
const outputConnectionNames = usertobeInserted.outputConnections.map(connection => connection.outputConnections);
|
|
|
|
for (const data of connection_data){
|
|
|
|
const existingInputConnections = tankInfo.connections.inputConnections.filter(connection =>
|
|
|
|
if(data['output_type'] === "overhead"){
|
|
|
|
outputConnectionNames.includes(connection.inputConnections)
|
|
|
|
const tankName = data['outputConnections']
|
|
|
|
);
|
|
|
|
const tank_info = await Tank.findOne({ customerId: customerId.toString(),tankName:tankName })
|
|
|
|
|
|
|
|
const connection_data_check =tank_info.connections.inputConnections
|
|
|
|
|
|
|
|
const sump_names=[]
|
|
|
|
|
|
|
|
for(const d of connection_data_check){
|
|
|
|
|
|
|
|
if (sump_names.includes(d.inputConnections)) {
|
|
|
|
|
|
|
|
console.log(`${d.inputConnections} exists in ${sump_names}`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sump_names.push(d.inputConnections)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const connection of existingInputConnections) {
|
|
|
|
|
|
|
|
connection.inputismotor = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(sump_names)
|
|
|
|
}
|
|
|
|
//tank_info.connections.inputConnections = tankname.toString()
|
|
|
|
|
|
|
|
if (sump_names.includes(tankname)) {
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
console.log(`${tankname} exists in ${sump_names}`);
|
|
|
|
|
|
|
|
|
|
|
|
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'];
|
|
|
|
|
|
|
|
console.log("data", data)
|
|
|
|
|
|
|
|
if (sump_names.includes(tankName)) {
|
|
|
|
|
|
|
|
console.log(`${tankName} exists in ${sump_names}`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const tankConnections = await Tank.findOneAndUpdate(
|
|
|
|
const tank_connections = await Tank.findOneAndUpdate(
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
{ $addToSet: { 'connections.inputConnections': { $each: [{ inputConnections: tankname, input_type: 'sump' }] } } },
|
|
|
|
{
|
|
|
|
|
|
|
|
$addToSet: {
|
|
|
|
|
|
|
|
'connections.inputConnections': {
|
|
|
|
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor }],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
'connections.outputConnections': {
|
|
|
|
|
|
|
|
$each: [{ outputConnections: tankname, output_type: 'overhead', outputismotor: data.outputismotor }],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
{ new: true }
|
|
|
|
{ new: true }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log("tankConnections", tank_connections.connections.inputConnections);
|
|
|
|
|
|
|
|
console.log("tankConnections", tank_connections.connections.outputConnections);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(tankConnections)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tank_connections = await tankInfo.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tank_connections;
|
|
|
|
return tank_connections;
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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.inputismotor,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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' }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead' }],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// { 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) => {
|
|
|
|
|
|
|
|
// 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.inputismotor,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
|
|
|
// outputismotor: connection.outputismotor,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
// await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
// { customerId: customerId.toString(), tankName: tankName },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// $addToSet: {
|
|
|
|
|
|
|
|
// 'connections.inputConnections': { inputConnections: tankname, input_type: 'sump' , inputismotor:tank_connections.connections.inputConnections},
|
|
|
|
|
|
|
|
// 'connections.outputConnections': { outputConnections: tankname, output_type: 'overhead', outputismotor : tank_connections.connections.outputConnections},
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// { new: true }
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return tank_connections;
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateconnectionInfo = async (req, reply) => {
|
|
|
|
exports.updateconnectionInfo = async (req, reply) => {
|
|
|
@ -107,7 +603,7 @@ exports.updateconnectionInfo = async (req, reply) => {
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
inputConnections: connection.inputConnections,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
input_type: connection.input_type,
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
inputismotor: connection.inputismotor // default to false if not specified
|
|
|
|
inputismotor: connection.inputismotor || false // default to false if not specified
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -118,7 +614,7 @@ exports.updateconnectionInfo = async (req, reply) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
outputismotor: connection.outputismotor // default to false if not specified
|
|
|
|
outputismotor: connection.outputismotor || false // default to false if not specified
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|