From 742f3c73d431ad1e5ab07229ba209df283f0ecd6 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Mon, 14 Jul 2025 12:35:23 +0530 Subject: [PATCH] master deatils in induvidual --- src/controllers/installationController.js | 86 ++++++++++++++++++++++- src/routes/installationRoute.js | 19 +++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 1346ed8b..9892a561 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -1771,7 +1771,7 @@ exports.masterConnectedSlaveList = async (req, reply) => { ...restMasterFields } = master; - + const masterResponse = { ...restMasterFields, hardwareId: masterHardwareId, // new field @@ -1849,6 +1849,90 @@ exports.masterConnectedSlaveList = async (req, reply) => { }; +exports.getTankDetailsByMaster = async (req, reply) => { + try { + const { customerId, hardwareId } = req.params; + + if (!customerId || !hardwareId) { + return reply.code(400).send({ + success: false, + message: 'customerId and hardwareId are required' + }); + } + + // Step 1: find master device (to confirm existence) + const masterDevice = await Insensors.findOne({ customerId, hardwareId, type: 'master' }).lean(); + if (!masterDevice) { + return reply.code(404).send({ + success: false, + message: 'Master device not found' + }); + } + + // Step 2: find order to get masterName & location + const orderRecord = await Order.findOne({ customerId, "master_connections.hardwareId": hardwareId }).lean(); + if (!orderRecord) { + return reply.code(404).send({ + success: false, + message: 'Order record not found for this hardwareId' + }); + } + + // find the master inside order + const masterInfo = orderRecord.master_connections.find( + m => m.hardwareId === hardwareId + ); + + const masterName = masterInfo ? masterInfo.master_name : null; + const location = masterInfo ? masterInfo.location : null; + + // Step 3: get tank details + const tank = await Tank.findOne({ customerId, hardwareId }).lean(); + if (!tank) { + return reply.code(404).send({ + success: false, + message: 'Tank details not found' + }); + } + + // Step 4: parse & format dimensions + const tankHeightFeet = parseInt(tank.height, 10); + const tankWidthFeet = parseInt(tank.width, 10); + const tankLengthFeet = parseInt(tank.length, 10); + + reply.send({ + success: true, + data: { + masterName: masterName, + location: location, + hardwareId: hardwareId, + tankName: tank.tankName, + blockName: tank.blockName, + shape: tank.shape, + capacity: tank.capacity, + waterCapacityPerCm: tank.waterCapacityPerCm, + typeOfWater: tank.typeOfWater, + tankLocation: tank.tankLocation, + height: tankHeightFeet, + width: tankWidthFeet, + length: tankLengthFeet, + heightInCm: tankHeightFeet * 30.48, + widthInCm: tankWidthFeet * 30.48, + lengthInCm: tankLengthFeet * 30.48 + } + }); + + } catch (error) { + console.error('Error fetching tank details:', error); + reply.code(500).send({ + success: false, + message: 'Internal server error' + }); + } +}; + + + exports.updateWorkStatusAndProductStatus = async (req, reply) => { diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 5e8b0d2a..3a16cff2 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -421,6 +421,25 @@ module.exports = function (fastify, opts, next) { }, handler: installationController.masterConnectedSlaveList, }); +fastify.get('/api/tanks/master/:customerId/:hardwareId', { + schema: { + tags: ['Tank'], + summary: 'Get tank details by master device', + description: 'Fetch tank details by providing customerId and hardwareId for type master', + + params: { + type: 'object', + required: ['customerId', 'hardwareId'], + properties: { + customerId: { type: 'string', }, + hardwareId: { type: 'string', } + } + }, + + + }, + handler: installationController.getTankDetailsByMaster +}); fastify.post(