|
|
@ -169,6 +169,55 @@ exports.deleteTanksInfo = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getConnectionsInfoOfParticularTank = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
const tankName = req.body.tankName;
|
|
|
|
|
|
|
|
const tankLocation = req.body.tankLocation.toLowerCase();
|
|
|
|
|
|
|
|
console.log(customerId,tankName,tankLocation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the specific tank
|
|
|
|
|
|
|
|
const mainTank = await Tank.findOne({
|
|
|
|
|
|
|
|
tankName: tankName,
|
|
|
|
|
|
|
|
customerId: customerId,
|
|
|
|
|
|
|
|
tankLocation: tankLocation
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mainTank) {
|
|
|
|
|
|
|
|
return reply.send({ status_code: 404, error: "Main tank not found" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to find tanks by name and location
|
|
|
|
|
|
|
|
const findTankDetails = async (connection, type) => {
|
|
|
|
|
|
|
|
return await Tank.findOne({
|
|
|
|
|
|
|
|
tankName: connection.inputConnections || connection.outputConnections,
|
|
|
|
|
|
|
|
tankLocation: connection.input_type || connection.output_type,
|
|
|
|
|
|
|
|
customerId: customerId
|
|
|
|
|
|
|
|
}).select('hardwareId tankName capacity height connections waterlevel');
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get all related input and output tanks
|
|
|
|
|
|
|
|
const inputTankPromises = mainTank.connections.inputConnections.map(input => findTankDetails(input, 'input'));
|
|
|
|
|
|
|
|
const outputTankPromises = mainTank.connections.outputConnections.map(output => findTankDetails(output, 'output'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resolve all promises
|
|
|
|
|
|
|
|
const inputTanks = await Promise.all(inputTankPromises);
|
|
|
|
|
|
|
|
const outputTanks = await Promise.all(outputTankPromises);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Combine data from the main tank and its connections
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
|
|
|
|
mainTank: mainTank,
|
|
|
|
|
|
|
|
inputConnections: inputTanks.filter(tank => tank !== null), // Filter out null results
|
|
|
|
|
|
|
|
outputConnections: outputTanks.filter(tank => tank !== null) // Filter out null results
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: result });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//get tanks data by passing username
|
|
|
|
//get tanks data by passing username
|
|
|
|
exports.getTank = async (req, reply) => {
|
|
|
|
exports.getTank = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|