This is to get Connections Info Of ParticularTank

master
varun 1 year ago
parent 51e5924128
commit eca056dc71

@ -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
exports.getTank = async (req, reply) => {
try {

@ -136,6 +136,45 @@ module.exports = function (fastify, opts, next) {
handler: tanksController.deleteTanksInfo,
});
fastify.route({
method: "PUT",
url: "/api/getConnectionsInfoOfParticularTank/:customerId",
schema: {
tags: ["Tank"],
summary: "This is to get Connections Info Of ParticularTank",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
tankName: {type: 'string'},
tankLocation: { type: "string", default: null },
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getConnectionsInfoOfParticularTank,
});
fastify.get("/api/getTanks", {
schema: {

Loading…
Cancel
Save