From 1f40da964559ba44698eea45cae9f84a485ae084 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 28 Jan 2025 15:27:49 +0530 Subject: [PATCH 1/3] changes in motordata --- src/controllers/tanksController.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5acde592..47d20f4c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -352,10 +352,17 @@ exports.getTanksofParticularInstaller = async (req, reply) => { exports.getTankmotordata = async (req, reply) => { try { - const { startDate, stopDate, block } = req.body; + const { startDate, stopDate } = req.body; const { customerId } = req.params; - const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate(); - const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate(); + + // Parse the input startDate and stopDate using the desired format + // const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate(); + // const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate(); + // console.log(start,"start",end,"end") + // Check if the parsed dates are valid + + // Convert the dates to the correct format for storage or querying (still in UTC) + // This gives a native JS Date object for querying // Fetch the name from the User collection based on customerId, only from profile const user = await User.findOne({ customerId }) @@ -370,14 +377,11 @@ exports.getTankmotordata = async (req, reply) => { // Construct the query object for motor data based on customerId const motorQuery = { customerId }; - // If block is provided (and not "All"), add it to the query - if (block !== "All") motorQuery.block = block; - // Fetch motor data for the customerId within the time range const motorDataDocs = await MotorData.find(motorQuery) - .where("date") - .gte(start) // Greater than or equal to startDate - .lte(end) // Less than or equal to stopDate + .where("startTime") + .gte(startDate) // Greater than or equal to startDate + .lte(stopDate) // Less than or equal to stopDate .exec(); reply.send({ @@ -396,6 +400,10 @@ exports.getTankmotordata = async (req, reply) => { + + + + exports.updateTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; From 92bf80d5c41ecbbe7b1d0adcecfb987cab744024 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 28 Jan 2025 15:28:26 +0530 Subject: [PATCH 2/3] changes --- src/controllers/tanksController.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 52e74091..f8cfd2ea 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -350,6 +350,7 @@ exports.getTanksofParticularInstaller = async (req, reply) => { // } //}; + exports.getTankmotordata = async (req, reply) => { try { const { startDate, stopDate } = req.body; From fb7b4e8751866a9c2b6b34b78dcef3c9baa70375 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 28 Jan 2025 15:57:54 +0530 Subject: [PATCH 3/3] changes in get motordata ,added user name --- src/controllers/tanksController.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f8cfd2ea..b09ceb9a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -351,6 +351,7 @@ exports.getTanksofParticularInstaller = async (req, reply) => { //}; + exports.getTankmotordata = async (req, reply) => { try { const { startDate, stopDate } = req.body; @@ -367,12 +368,12 @@ exports.getTankmotordata = async (req, reply) => { // Fetch the name from the User collection based on customerId, only from profile const user = await User.findOne({ customerId }) - .select("profile.firstName profile.lastName"); + .select("username"); if (user) { // Get the full name (combine firstName and lastName if available) - const userName = user.profile.firstName && user.profile.lastName - ? `${user.profile.firstName} ${user.profile.lastName}` + const userName = user.username + ? `${user.username}` : "N/A"; // Fallback if no name is found // Construct the query object for motor data based on customerId