|
|
@ -370,6 +370,88 @@ 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: "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, body) => {
|
|
|
|
exports.createConnections = async (req, body) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const customerId = req.params.customerId;
|
|
|
@ -384,8 +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: "0",
|
|
|
|
motor_status: connection.motor_status || "0",
|
|
|
|
inputismotor: connection.inputismotor,
|
|
|
|
inputismotor: connection.hasOwnProperty("inputismotor") ? connection.inputismotor : false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -395,19 +477,9 @@ exports.createConnections = async (req, body) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
outputConnections: connection.outputConnections,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
output_type: connection.output_type,
|
|
|
|
motor_status: "0",
|
|
|
|
outputismotor: connection.hasOwnProperty("outputismotor") ? connection.outputismotor : false,
|
|
|
|
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 tank_connections = await tankInfo.save();
|
|
|
@ -421,26 +493,26 @@ exports.createConnections = async (req, body) => {
|
|
|
|
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'];
|
|
|
|
console.log("data", data)
|
|
|
|
|
|
|
|
if (sump_names.includes(tankName)) {
|
|
|
|
if (sump_names.includes(tankname)) {
|
|
|
|
console.log(`${tankName} exists in ${sump_names}`);
|
|
|
|
console.log(`${tankname} exists in ${sump_names}`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const tank_connections = await Tank.findOneAndUpdate(
|
|
|
|
const tankConnections = await Tank.findOneAndUpdate(
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
{ customerId: customerId.toString(), tankName: tankName },
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$addToSet: {
|
|
|
|
$addToSet: {
|
|
|
|
'connections.inputConnections': {
|
|
|
|
'connections.inputConnections': {
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor }],
|
|
|
|
$each: [{ inputConnections: tankname, input_type: 'sump', inputismotor: data.outputismotor || false }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'connections.outputConnections': {
|
|
|
|
'connections.outputConnections': {
|
|
|
|
$each: [{ outputConnections: tankname, output_type: 'overhead' }],
|
|
|
|
$each: [{ outputConnections: tankname, output_type: 'overhead'}],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ new: true }
|
|
|
|
{ new: true }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
console.log("tankConnections", tank_connections.connections.inputConnections);
|
|
|
|
console.log("tankConnections", tankConnections.connections.inputConnections);
|
|
|
|
console.log("tankConnections", tank_connections.connections.outputConnections);
|
|
|
|
console.log("tankConnections", tankConnections.connections.outputConnections);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -451,6 +523,8 @@ 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;
|
|
|
|