From 07b013e71224fca5060c3c57ad59664c769ba496 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 23 Apr 2025 16:05:59 +0530 Subject: [PATCH] changes --- src/controllers/installationController.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 426b570c..a03a08fe 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -1457,7 +1457,6 @@ exports.mastrerList = async (req, reply) => { // } // }; - exports.getMasterSlaveSummary = async (req, reply) => { try { const { customerId } = req.params; @@ -1466,6 +1465,7 @@ exports.getMasterSlaveSummary = async (req, reply) => { return reply.status(400).send({ error: 'customerId is required' }); } + // Fetch all devices for the customer const allDevices = await Insensors.find({ customerId }).lean(); const masters = allDevices.filter(dev => dev.type === 'master'); @@ -1473,6 +1473,7 @@ exports.getMasterSlaveSummary = async (req, reply) => { const slaveMap = {}; + // Process each slave for (const slave of slaves) { const masterId = slave.connected_to; if (!slaveMap[masterId]) { @@ -1488,12 +1489,15 @@ exports.getMasterSlaveSummary = async (req, reply) => { // If disconnected, update LoRa last disconnect time let loraLastDisconnect = slave.lora_last_disconnect_time || null; if (slave.connected_status === 'disconnected') { - const now = moment().tz('Asia/Kolkata').format('YYYY-MM-DD HH:mm:ss'); + const date = slave.connected_lora_date || moment().tz('Asia/Kolkata').format('YYYY-MM-DD'); + const time = slave.connected_lora_time || moment().tz('Asia/Kolkata').format('HH:mm:ss'); + const combined = `${date} ${time}`; + await Insensors.updateOne( { hardwareId: slave.hardwareId }, - { $set: { lora_last_disconnect_time: now } } + { $set: { lora_last_disconnect_time: combined } } ); - loraLastDisconnect = now; + loraLastDisconnect = combined; } // Get tankHeight from IotData @@ -1518,18 +1522,22 @@ exports.getMasterSlaveSummary = async (req, reply) => { const response = []; + // Process each master for (const master of masters) { const connectedSlaves = slaveMap[master.hardwareId] || []; // If disconnected, update GSM last disconnect time let gsmLastDisconnect = master.gsm_last_disconnect_time || null; if (master.connected_status === 'disconnected') { - const now = moment().tz('Asia/Kolkata').format('YYYY-MM-DD HH:mm:ss'); + const date = master.connected_gsm_date || moment().tz('Asia/Kolkata').format('YYYY-MM-DD'); + const time = master.connected_gsm_time || moment().tz('Asia/Kolkata').format('HH:mm:ss'); + const combined = `${date} ${time}`; + await Insensors.updateOne( { hardwareId: master.hardwareId }, - { $set: { gsm_last_disconnect_time: now } } + { $set: { gsm_last_disconnect_time: combined } } ); - gsmLastDisconnect = now; + gsmLastDisconnect = combined; } const enriched = { @@ -1582,6 +1590,7 @@ async function getTankHeight(hardwareId) { } + // exports.getIotDataByCustomer = async (req, reply) => { // try { // const { customerId } = req.params;