From 0da6e85ce83f665c26e07c959ae528ae7472d7c2 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 11 Jul 2025 09:47:08 +0530 Subject: [PATCH] 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(