From aa8bfc04f4d7589817dbb2a1001311ed0944a3fc Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 11 Jul 2025 00:12:51 +0530 Subject: [PATCH 1/2] Individual data of master and slaves --- src/controllers/installationController.js | 43 +++++++++++++ src/routes/installationRoute.js | 75 +++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 7a6f91da..b767a4cf 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -3095,6 +3095,49 @@ exports.getWaitingMasterSlaveSummary = async (req, reply) => { } }; +exports.getMasterWithSlaves = async (req, reply) => { + try { + const { installationId, customerId, hardwareId } = req.params; + + if (!installationId || !customerId || !hardwareId) { + return reply.code(400).send({ success: false, message: "installationId, customerId, and hardwareId are required" }); + } + + // Find order + const order = await Order.findOne({ installationId, customerId }).lean(); + if (!order) { + return reply.code(404).send({ success: false, message: "Order not found" }); + } + + // Find master device in Insensors + const master = await Insensors.findOne({ + hardwareId, + customerId, + }).lean(); + + if (!master) { + return reply.code(404).send({ success: false, message: "Master device not found in Insensors" }); + } + + // // Find slaves connected to this master + // const slaves = await Insensors.find({ + // connected_to: hardwareId, + // customerId, + // type: 'slave' + // }).lean(); + + return reply.send({ + success: true, + master, + }); + + } catch (error) { + console.error("Error fetching master and slaves:", error); + return reply.code(500).send({ success: false, message: "Internal server error" }); + } +}; + + exports.getPendingMasterSlaveSummary = async (req, reply) => { try { const { customerId } = req.params; diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 817a021c..49dc284c 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -593,6 +593,81 @@ fastify.post( handler: installationController.getMasterSlaveSummary, }); + fastify.get('/api/master-with-slaves/:installationId/:customerId/:hardwareId', { + schema: { + tags: ['Installation'], + summary: 'Get Individual master device and its connected slaves', + description: 'Fetch a master device from Insensors by hardwareId and list all connected slave devices for the same customer and installation.', + params: { + type: 'object', + required: ['installationId', 'customerId', 'hardwareId'], + properties: { + installationId: { type: 'string', description: 'Installation ID from Order' }, + customerId: { type: 'string', description: 'Customer ID' }, + hardwareId: { type: 'string', description: 'Master hardwareId' }, + } + }, + // response: { + // 200: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // master: { + // type: 'object', + // description: 'Master device details', + // properties: { + // _id: { type: 'string' }, + // hardwareId: { type: 'string' }, + // customerId: { type: 'string' }, + // type: { type: 'string' }, + // // Add other master fields as needed... + // } + // }, + // slaves: { + // type: 'array', + // description: 'List of connected slave devices', + // items: { + // type: 'object', + // properties: { + // _id: { type: 'string' }, + // hardwareId: { type: 'string' }, + // connected_to: { type: 'string' }, + // customerId: { type: 'string' }, + // type: { type: 'string' }, + // // Add other slave fields as needed... + // } + // } + // } + // } + // }, + // 400: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' } + // } + // }, + // 404: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' } + // } + // }, + // 500: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' } + // } + // } + // } + }, + handler: installationController.getMasterWithSlaves, + +}); + + fastify.get("/api/getwaitingmasterlistwithslaves/:customerId", { schema: { description: "Get waiting manager masrter connected slave data with full info", From 0da6e85ce83f665c26e07c959ae528ae7472d7c2 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 11 Jul 2025 09:47:08 +0530 Subject: [PATCH 2/2] update the tank dimensions --- src/controllers/installationController.js | 79 +++++++++++++++++++++++ src/routes/installationRoute.js | 30 ++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index b767a4cf..33e6bcff 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -3137,6 +3137,85 @@ exports.getMasterWithSlaves = async (req, reply) => { } }; +exports.editTankDimensions = async (req, reply) => { + try { + const { customerId, teamMemberId, hardwareId, tankHardwareId } = req.params; + const { height, width, length } = req.body; + + if (!customerId || !teamMemberId || !hardwareId || !tankHardwareId) { + return reply.code(400).send({ + success: false, + message: 'customerId, teamMemberId, hardwareId and tankHardwareId are required' + }); + } + + // if (!height || !width || !length) { + // return reply.code(400).send({ + // success: false, + // message: 'height, width and length are required in body' + // }); + // } + + // Step 1: Find install record with teamMemberId (must be assigned) + const installRecord = await Install.findOne({ + 'team_member.team_member.teamMemberId': teamMemberId + }).lean(); + + if (!installRecord) { + return reply.code(404).send({ + success: false, + message: 'Team member not found or not assigned' + }); + } + + // Step 2: Find the matching order using installationId from install and customerId + const orderRecord = await Order.findOne({ + installationId: installRecord.installationId, + customerId + }).lean(); + + if (!orderRecord) { + return reply.code(404).send({ + success: false, + message: 'Order not found for this installation and customer' + }); + } + + // Step 3: Update the tank document in Tanks collection + const updatedTank = await Tank.findOneAndUpdate( + { + customerId, + hardwareId, + tankhardwareId: tankHardwareId + }, + { + $set: { height, width, length } + }, + { new: true } + ).lean(); + + if (!updatedTank) { + return reply.code(404).send({ + success: false, + message: 'Tank not found with given customerId, hardwareId and tankHardwareId' + }); + } + + return reply.send({ + success: true, + message: 'Tank dimensions updated successfully', + updatedTank + }); + + } catch (error) { + console.error('Error updating tank dimensions:', error); + return reply.code(500).send({ + success: false, + message: 'Internal server error' + }); + } +}; + exports.getPendingMasterSlaveSummary = async (req, reply) => { try { diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 49dc284c..3f2b5c73 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -445,7 +445,7 @@ module.exports = function (fastify, opts, next) { properties: { work_status: { type: 'string', - enum: ['active', 'pending', 'complete','waiting'], // update enum based on what your Orders schema allows + enum: ['active', 'pending', 'complete','waiting','reject'], // update enum based on what your Orders schema allows description: 'New work status to set in master_connections' } } @@ -482,6 +482,34 @@ module.exports = function (fastify, opts, next) { } ); +fastify.put('/api/tanks/:customerId/:teamMemberId/:hardwareId/:tankHardwareId', { + schema: { + tags: ['Installation'], + summary: 'Update tank dimensions', + description: 'Edit tank details (height, width, length) by customerId, teamMemberId, hardwareId and tankHardwareId.', + params: { + type: 'object', + required: ['customerId', 'teamMemberId', 'hardwareId', 'tankHardwareId'], + properties: { + customerId: { type: 'string', description: 'Customer ID' }, + teamMemberId: { type: 'string', description: 'Team member ID' }, + hardwareId: { type: 'string', description: 'Master hardwareId' }, + tankHardwareId: { type: 'string', description: 'Tank hardwareId' } + } + }, + body: { + type: 'object', + //required: ['height', 'width', 'length'], + properties: { + height: { type: 'string', description: 'New tank height' }, + width: { type: 'string', description: 'New tank width' }, + length: { type: 'string', description: 'New tank length' } + } + }, + + }, + handler : installationController.editTankDimensions +}); fastify.post(