From 4ee66c185bbfbfecca5e5c681d3c4cbc5f5151b0 Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 16 May 2025 17:18:04 +0530 Subject: [PATCH 1/4] changes --- src/controllers/tanksController.js | 100 ++++++++++++++--------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 57e541c8..c6d54b23 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -6217,61 +6217,61 @@ async function processIotData(hw_Id, data) { console.log(`🚰 Tank [${tankhardwareId}] - Level: ${tankHeight}, Calculated Water Level: ${waterLevel}`); const now = moment().tz('Asia/Kolkata'); - if (tankHeight <= 0) { - // Case 1: First time signal is lost - if ( - existingTank.slave_status !== "signal_lost1" && - existingTank.slave_status !== "not_working" - ) { - existingTank.slave_status = "signal_lost1"; - existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); - await existingTank.save(); + // if (tankHeight <= 0) { + // // Case 1: First time signal is lost + // if ( + // existingTank.slave_status !== "signal_lost1" && + // existingTank.slave_status !== "not_working" + // ) { + // existingTank.slave_status = "signal_lost1"; + // existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); + // await existingTank.save(); - console.log(`⚠️ Signal lost for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); - return; // Important: do not continue in this cycle + // console.log(`⚠️ Signal lost for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); + // return; // Important: do not continue in this cycle - } else if (existingTank.slave_status === "signal_lost1") { - if (!existingTank.slave_disconnected_time) { - console.log(`❗ Missing slave_disconnected_time despite signal_lost1 for tank [${tankhardwareId}]`); - return; - } + // } else if (existingTank.slave_status === "signal_lost1") { + // if (!existingTank.slave_disconnected_time) { + // console.log(`❗ Missing slave_disconnected_time despite signal_lost1 for tank [${tankhardwareId}]`); + // return; + // } - const lostTime = moment(existingTank.slave_disconnected_time, 'DD-MMM-YYYY - HH:mm:ss'); - const minutesElapsed = now.diff(lostTime, 'minutes'); + // const lostTime = moment(existingTank.slave_disconnected_time, 'DD-MMM-YYYY - HH:mm:ss'); + // const minutesElapsed = now.diff(lostTime, 'minutes'); - if (minutesElapsed >= 15) { - existingTank.slave_status = "not_working"; - existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); - await existingTank.save(); + // if (minutesElapsed >= 15) { + // existingTank.slave_status = "not_working"; + // existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); + // await existingTank.save(); - console.log(`❌ Slave marked as not_working for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); + // console.log(`❌ Slave marked as not_working for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); - // Update connected output tanks - for (const outputConnection of existingTank.connections.outputConnections) { - const linkedTank = await Tank.findOne({ - customerId, - tankName: outputConnection.outputConnections, - tankLocation: outputConnection.output_type - }); + // // Update connected output tanks + // for (const outputConnection of existingTank.connections.outputConnections) { + // const linkedTank = await Tank.findOne({ + // customerId, + // tankName: outputConnection.outputConnections, + // tankLocation: outputConnection.output_type + // }); - if (linkedTank) { - for (const inputConnection of linkedTank.connections.inputConnections) { - if (inputConnection.inputConnections === tank_name) { - inputConnection.slave_status = "not_working"; - await linkedTank.save(); - console.log(`🔗 Linked tank [${linkedTank.tankName}] inputConnection updated to not_working`); - } - } - } - } + // if (linkedTank) { + // for (const inputConnection of linkedTank.connections.inputConnections) { + // if (inputConnection.inputConnections === tank_name) { + // inputConnection.slave_status = "not_working"; + // await linkedTank.save(); + // console.log(`🔗 Linked tank [${linkedTank.tankName}] inputConnection updated to not_working`); + // } + // } + // } + // } - } else { - console.log(`⏳ Still within 15-minute grace: ${minutesElapsed} minutes elapsed for tank [${tankhardwareId}]`); - } - } else { - console.log(`⏩ Tank [${tankhardwareId}] already marked as ${existingTank.slave_status}, skipping update.`); - } - } + // } else { + // console.log(`⏳ Still within 15-minute grace: ${minutesElapsed} minutes elapsed for tank [${tankhardwareId}]`); + // } + // } else { + // console.log(`⏩ Tank [${tankhardwareId}] already marked as ${existingTank.slave_status}, skipping update.`); + // } + // } @@ -6280,8 +6280,8 @@ async function processIotData(hw_Id, data) { if (tankHeight > 0 && waterLevel >= 0) { existingTank.waterlevel = waterLevel; - existingTank.slave_status = "working"; - existingTank.slave_disconnected_time = null; + // existingTank.slave_status = "working"; + // existingTank.slave_disconnected_time = null; await existingTank.save(); for (const outputConnection of existingTank.connections.outputConnections) { @@ -6290,7 +6290,7 @@ async function processIotData(hw_Id, data) { for (const inputConnection of linkedTank.connections.inputConnections) { if (inputConnection.inputConnections === tank_name) { inputConnection.water_level = waterLevel; - inputConnection. slave_status = "working"; + ` // inputConnection. slave_status = "working";` await linkedTank.save(); } } From 479d29248d3faf3a49afa0a70743dcde1cc1832d Mon Sep 17 00:00:00 2001 From: Varun Date: Sun, 18 May 2025 14:10:35 +0530 Subject: [PATCH 2/4] changes --- src/controllers/tanksController.js | 100 ++++++++++++++--------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index c6d54b23..7414b0f0 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -6217,61 +6217,61 @@ async function processIotData(hw_Id, data) { console.log(`🚰 Tank [${tankhardwareId}] - Level: ${tankHeight}, Calculated Water Level: ${waterLevel}`); const now = moment().tz('Asia/Kolkata'); - // if (tankHeight <= 0) { - // // Case 1: First time signal is lost - // if ( - // existingTank.slave_status !== "signal_lost1" && - // existingTank.slave_status !== "not_working" - // ) { - // existingTank.slave_status = "signal_lost1"; - // existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); - // await existingTank.save(); + if (tankHeight <= 0) { + // Case 1: First time signal is lost + if ( + existingTank.slave_status !== "signal_lost1" && + existingTank.slave_status !== "not_working1" + ) { + existingTank.slave_status = "signal_lost1"; + existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); + await existingTank.save(); - // console.log(`⚠️ Signal lost for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); - // return; // Important: do not continue in this cycle + console.log(`⚠️ Signal lost for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); + return; // Important: do not continue in this cycle - // } else if (existingTank.slave_status === "signal_lost1") { - // if (!existingTank.slave_disconnected_time) { - // console.log(`❗ Missing slave_disconnected_time despite signal_lost1 for tank [${tankhardwareId}]`); - // return; - // } + } else if (existingTank.slave_status === "signal_lost1") { + if (!existingTank.slave_disconnected_time) { + console.log(`❗ Missing slave_disconnected_time despite signal_lost1 for tank [${tankhardwareId}]`); + return; + } - // const lostTime = moment(existingTank.slave_disconnected_time, 'DD-MMM-YYYY - HH:mm:ss'); - // const minutesElapsed = now.diff(lostTime, 'minutes'); + const lostTime = moment(existingTank.slave_disconnected_time, 'DD-MMM-YYYY - HH:mm:ss'); + const minutesElapsed = now.diff(lostTime, 'minutes'); - // if (minutesElapsed >= 15) { - // existingTank.slave_status = "not_working"; - // existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); - // await existingTank.save(); + if (minutesElapsed >= 15) { + existingTank.slave_status = "not_working1"; + existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss'); + await existingTank.save(); - // console.log(`❌ Slave marked as not_working for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); + console.log(`❌ Slave marked as not_working for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`); - // // Update connected output tanks - // for (const outputConnection of existingTank.connections.outputConnections) { - // const linkedTank = await Tank.findOne({ - // customerId, - // tankName: outputConnection.outputConnections, - // tankLocation: outputConnection.output_type - // }); + // Update connected output tanks + for (const outputConnection of existingTank.connections.outputConnections) { + const linkedTank = await Tank.findOne({ + customerId, + tankName: outputConnection.outputConnections, + tankLocation: outputConnection.output_type + }); - // if (linkedTank) { - // for (const inputConnection of linkedTank.connections.inputConnections) { - // if (inputConnection.inputConnections === tank_name) { - // inputConnection.slave_status = "not_working"; - // await linkedTank.save(); - // console.log(`🔗 Linked tank [${linkedTank.tankName}] inputConnection updated to not_working`); - // } - // } - // } - // } + if (linkedTank) { + for (const inputConnection of linkedTank.connections.inputConnections) { + if (inputConnection.inputConnections === tank_name) { + inputConnection.slave_status = "not_working1"; + await linkedTank.save(); + console.log(`🔗 Linked tank [${linkedTank.tankName}] inputConnection updated to not_working`); + } + } + } + } - // } else { - // console.log(`⏳ Still within 15-minute grace: ${minutesElapsed} minutes elapsed for tank [${tankhardwareId}]`); - // } - // } else { - // console.log(`⏩ Tank [${tankhardwareId}] already marked as ${existingTank.slave_status}, skipping update.`); - // } - // } + } else { + console.log(`⏳ Still within 15-minute grace: ${minutesElapsed} minutes elapsed for tank [${tankhardwareId}]`); + } + } else { + console.log(`⏩ Tank [${tankhardwareId}] already marked as ${existingTank.slave_status}, skipping update.`); + } + } @@ -6280,8 +6280,8 @@ async function processIotData(hw_Id, data) { if (tankHeight > 0 && waterLevel >= 0) { existingTank.waterlevel = waterLevel; - // existingTank.slave_status = "working"; - // existingTank.slave_disconnected_time = null; + existingTank.slave_status = "working"; + existingTank.slave_disconnected_time = null; await existingTank.save(); for (const outputConnection of existingTank.connections.outputConnections) { @@ -6290,7 +6290,7 @@ async function processIotData(hw_Id, data) { for (const inputConnection of linkedTank.connections.inputConnections) { if (inputConnection.inputConnections === tank_name) { inputConnection.water_level = waterLevel; - ` // inputConnection. slave_status = "working";` + inputConnection. slave_status = "working"; await linkedTank.save(); } } From 0881ed03fa61bdee65b2e2f2c5bef18fdd1d270e Mon Sep 17 00:00:00 2001 From: Varun Date: Mon, 19 May 2025 11:29:27 +0530 Subject: [PATCH 3/4] changes in qc check --- src/controllers/storeController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index cbcf2f24..586dbfaf 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1317,7 +1317,7 @@ exports.updateSensorQC = async (req, reply) => { // Ensure qccheck is handled properly if (filteredUpdateData.qccheck) { const qccheckLower = filteredUpdateData.qccheck.toLowerCase(); - filteredUpdateData.status = qccheckLower === 'Pass' ? 'available' : 'qcfailed'; + filteredUpdateData.status = qccheckLower === 'pass' ? 'available' : 'qcfailed'; } // Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format From 1eb4c3fccbb58b4fa4f3944f43ae56ed20d7b7a7 Mon Sep 17 00:00:00 2001 From: Varun Date: Mon, 19 May 2025 11:40:04 +0530 Subject: [PATCH 4/4] changes in accept quotation --- src/models/store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/store.js b/src/models/store.js index b5a2291a..13ab1e19 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -444,6 +444,7 @@ const insensorsSchema = new mongoose.Schema({ connected_status: { type: String, enum: ["connected", "Not connected", "unknown"], default: "unknown" }, masterName: { type: String, default: null }, location: { type: String, default: null }, + tankhardwareId: { type: String, default: null }, motor_switches: [ { from_tank: { type: String, default: null },