From 132a8bb9eac63f18acbd82c8b4043d5bd520a719 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 10 Jul 2025 22:47:33 +0530 Subject: [PATCH] waiting for response manger --- src/controllers/installationController.js | 46 +++++++++++++++++ src/routes/installationRoute.js | 63 +++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 4f9a5908..906d8057 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -1935,6 +1935,52 @@ return { }; +exports.updateWorkStatusAndProductStatus = async (req, reply) => { + try { + const { connectedTo, teamMemberId, customerId } = req.params; + const { work_status } = req.body; + + if (!connectedTo || !teamMemberId || !customerId) { + return reply.status(400).send({ success: false, message: "connectedTo, teamMemberId, and customerId are required" }); + } + + if (!work_status) { + return reply.status(400).send({ success: false, message: "work_status is required in body" }); + } + + // Step 1: Update work_status in Order schema + const orderUpdate = await Order.updateOne( + { customerId, "master_connections.hardwareId": connectedTo }, + { $set: { "master_connections.$.work_status": work_status } } + ); + + // Step 2: Update master product_status + const masterUpdate = await Insensors.updateOne( + { hardwareId: connectedTo, type: 'master', customerId }, + { $set: { product_status: 'complete', team_member_support_gsm_last_check_time: new Date().toISOString() } } + ); + + // Step 3: Update all connected slaves product_status + const slaveUpdate = await Insensors.updateMany( + { connected_to: connectedTo, type: 'slave', customerId }, + { $set: { product_status: 'complete', team_member_support_lora_last_check_time: new Date().toISOString() } } + ); + + return reply.send({ + success: true, + message: 'Work status and product_status updated successfully', + orderMatchedCount: orderUpdate.matchedCount, + orderModifiedCount: orderUpdate.modifiedCount, + masterModifiedCount: masterUpdate.modifiedCount, + slaveModifiedCount: slaveUpdate.modifiedCount + }); + } catch (error) { + console.error('Error updating work_status and product_status:', error); + return reply.status(500).send({ success: false, message: 'Internal Server Error' }); + } +}; + + // exports.addMediaToInsensor = async (req, reply) => { // try { // const { hardwareId, customerId, type } = req.params; diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 9ffe13f5..ea4bbdd3 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -421,6 +421,69 @@ module.exports = function (fastify, opts, next) { }, handler: installationController.masterConnectedSlaveList, }); + + + fastify.post( + '/api/update-status/:connectedTo/:teamMemberId/:customerId', + { + schema: { + description: 'Update work_status in Order and set product_status to complete for master and connected slaves', + summary: 'Update work_status in Order and set product_status to complete for master and connected slaves', + tags: ['Installation'], + params: { + type: 'object', + required: ['connectedTo', 'teamMemberId', 'customerId'], + properties: { + connectedTo: { type: 'string', description: 'Master hardwareId' }, + teamMemberId: { type: 'string', description: 'Team member ID' }, + customerId: { type: 'string', description: 'Customer ID' } + } + }, + body: { + type: 'object', + required: ['work_status'], + properties: { + work_status: { + type: 'string', + enum: ['active', 'pending', 'complete','waiting'], // update enum based on what your Orders schema allows + description: 'New work status to set in master_connections' + } + } + }, + // response: { + // 200: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' }, + // orderMatchedCount: { type: 'integer' }, + // orderModifiedCount: { type: 'integer' }, + // masterModifiedCount: { type: 'integer' }, + // slaveModifiedCount: { type: 'integer' } + // } + // }, + // 400: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' } + // } + // }, + // 500: { + // type: 'object', + // properties: { + // success: { type: 'boolean' }, + // message: { type: 'string' } + // } + // } + // } + }, + handler: installationController.updateWorkStatusAndProductStatus + + } +); + + fastify.post( '/api/insensors/media/:customerId', {