From cbe5683cdd107e08a697516a8d61cfef0b344513 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 17 Oct 2024 14:10:35 +0530 Subject: [PATCH] CHANGES --- src/controllers/tanksController.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 3467b622..efbe2877 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -4453,7 +4453,7 @@ exports.consumptionofparticulartank = async (request, reply) => { customerId, tankName, tankLocation: tankLocation, - }).sort({ time: 1 }); + }); // Filter records in JavaScript by comparing the 'time' field after converting to Date const filteredConsumptions = tankConsumptions.filter((record) => { @@ -4461,6 +4461,13 @@ exports.consumptionofparticulartank = async (request, reply) => { return recordTime >= start && recordTime <= end; }); + // Sort filtered records by date (ascending) + filteredConsumptions.sort((a, b) => { + const dateA = moment(a.time, "DD-MMM-YYYY - HH:mm").toDate(); + const dateB = moment(b.time, "DD-MMM-YYYY - HH:mm").toDate(); + return dateA - dateB; // Sort in ascending order + }); + // Calculate total consumption from filtered records const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => { return acc + parseInt(record.consumption, 10); @@ -4496,3 +4503,5 @@ exports.consumptionofparticulartank = async (request, reply) => { + +