From b77f397790c086119d8717530e8502e0b1186a28 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 5 Sep 2024 15:35:38 +0530 Subject: [PATCH] changes --- src/controllers/tanksController.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 731f7c35..3714516a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -969,7 +969,7 @@ exports.consumption = async (request, reply) => { const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const tankname = tank.tankName; - const tankConsumptions = await TankConsumptionSchema.find({ + const tankConsumptions = await TankConsumptionOriginalSchema.find({ customerId, tankName: tank.tankName, tankLocation: tank.tankLocation, @@ -3437,13 +3437,15 @@ const updatetotalConsumptiontillmidnight = async () => { const waterlevel_at_midnight = parseInt((tank.waterlevel_at_midnight).replace(/,/g, ''), 10); const total_water_added_from_midnight = parseInt((tank.total_water_added_from_midnight).replace(/,/g, ''), 10); const waterlevel = parseInt((tank.waterlevel).replace(/,/g, ''), 10); + console.log(waterlevel_at_midnight,total_water_added_from_midnight,waterlevel) const totalconsumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel; + console.log(totalconsumption,tank.tankName) // Format the date in the desired format const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); // Check if the record already exists - const existingRecord = await TankConsumptionOriginalSchema.findOne({ + const existingRecord = await TankConsumptionSchema.findOne({ customerId: tank.customerId, tankName: tank.tankName, tankLocation: tank.tankLocation, @@ -3452,7 +3454,7 @@ const updatetotalConsumptiontillmidnight = async () => { if (!existingRecord) { // Create and save the new document if it doesn't exist - const newTankConsumption = new TankConsumptionOriginalSchema({ + const newTankConsumption = new TankConsumptionSchema({ customerId: tank.customerId, tankName: tank.tankName, tankLocation: tank.tankLocation, @@ -3478,7 +3480,7 @@ const updatetotalConsumptiontillmidnight = async () => { clearConsumptionSchedule(); // Schedule the task to run every day at 12:49 PM IST and store the reference -consumptionTask = cron.schedule('55 23 * * *', updatetotalConsumptiontillmidnight, { +consumptionTask = cron.schedule('32 15 * * *', updatetotalConsumptiontillmidnight, { timezone: "Asia/Kolkata" }); @@ -3900,10 +3902,16 @@ exports.getBlockData = async (req, reply) => { // Remove duplicates by converting the array to a Set and then back to an array const uniqueBlockNames = [...new Set(blockNames)]; + // Add "all" and "nduku sneha antha kopam" to the block names + uniqueBlockNames.unshift("All", "nduku sneha antha kopam","em sadistav cheppu"); + // Send the unique blockNames in the response reply.code(200).send({ blockNames: uniqueBlockNames }); } catch (err) { + // Log the error for debugging purposes + console.error(err); + // Send an error response reply.code(500).send({ error: err.message }); }