|
|
|
@ -10,500 +10,6 @@ const fastify = require("fastify")({
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) => {
|
|
|
|
|
// 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: "0",
|
|
|
|
|
// inputismotor: connection.inputismotor,
|
|
|
|
|
// };
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (usertobeInserted.outputConnections) {
|
|
|
|
|
// tankInfo.connections.outputConnections = usertobeInserted.outputConnections.map(connection => {
|
|
|
|
|
// return {
|
|
|
|
|
// outputConnections: connection.outputConnections,
|
|
|
|
|
// output_type: connection.output_type,
|
|
|
|
|
// motor_status: "0",
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
// const tank_connections = await Tank.findOneAndUpdate(
|
|
|
|
|
// { customerId: customerId.toString(), tankName: tankName },
|
|
|
|
|
// {
|
|
|
|
|
// $addToSet: {
|
|
|
|
|
// 'connections.inputConnections': {
|
|
|
|
|
// $each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor }],
|
|
|
|
|
// },
|
|
|
|
|
// 'connections.outputConnections': {
|
|
|
|
|
// $each: [{ outputConnections: tankname, output_type: 'overhead' }],
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// { new: true }
|
|
|
|
|
// );
|
|
|
|
|
// console.log("tankConnections", tank_connections.connections.inputConnections);
|
|
|
|
|
// console.log("tankConnections", tank_connections.connections.outputConnections);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return tank_connections;
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.createConnections = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const customerId = req.params.customerId;
|
|
|
|
|
// const tankname = req.body.tankname;
|
|
|
|
|
|
|
|
|
|
// // Retrieve the tank or return an error if it's not found
|
|
|
|
|
// const tankInfo = await Tank.findOne({ customerId: customerId.toString(), tankName: tankname });
|
|
|
|
|
// if (!tankInfo) {
|
|
|
|
|
// return reply.send({ status_code: 404, error: "Tank not found" });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Update the source tank info
|
|
|
|
|
// tankInfo.connections.source = tankname;
|
|
|
|
|
|
|
|
|
|
// // Handle input connections
|
|
|
|
|
// if (req.body.inputConnections) {
|
|
|
|
|
// tankInfo.connections.inputConnections = req.body.inputConnections.map(connection => ({
|
|
|
|
|
// inputConnections: connection.inputConnections,
|
|
|
|
|
// input_type: connection.input_type,
|
|
|
|
|
// 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,
|
|
|
|
|
// capacity: connection.capacity || null,
|
|
|
|
|
// water_level: connection.water_level || null
|
|
|
|
|
// }));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Handle output connections
|
|
|
|
|
// if (req.body.outputConnections) {
|
|
|
|
|
// tankInfo.connections.outputConnections = req.body.outputConnections.map(connection => ({
|
|
|
|
|
// 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
|
|
|
|
|
// }));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Save the updated tank connections
|
|
|
|
|
// const updatedTankConnections = await tankInfo.save();
|
|
|
|
|
// console.log("Updated Tank Connections:", updatedTankConnections.connections);
|
|
|
|
|
|
|
|
|
|
// // Send the updated tank connections as the response
|
|
|
|
|
// return reply.send({ status_code: 200, data: updatedTankConnections });
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -646,139 +152,6 @@ exports.createConnections = async (req, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) => {
|
|
|
|
|
try {
|
|
|
|
@ -860,30 +233,3 @@ exports.getConnections = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.createConnectionsforOh = async (req, body) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const customerId = req.params.customerId;
|
|
|
|
|
// var tankname = req.body.tankname;
|
|
|
|
|
|
|
|
|
|
// const tankInfo = await Tank.findOne({ customerId: customerId.toString(),tankName:tankname ,tankLocation:"sump"})
|
|
|
|
|
// const connection_data = tankinfo.connections.outputConnections
|
|
|
|
|
// for (data in connection_data) {
|
|
|
|
|
// console.log(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// // const usertobeInserted = req.body;
|
|
|
|
|
// //tankInfo.connections.source = tankInfo.tankName;
|
|
|
|
|
// //if (usertobeInserted.inputConnections) tankInfo.connections.inputConnections = usertobeInserted.inputConnections;
|
|
|
|
|
// //if (usertobeInserted.outputConnections) tankInfo.connections.outputConnections = usertobeInserted.outputConnections;
|
|
|
|
|
// //const tank_connections = await tankInfo.save();
|
|
|
|
|
// // return tank_connections;
|
|
|
|
|
// } catch (err) {.
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|