|
|
|
@ -1184,11 +1184,19 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
...(typeofwater === "drinking" && { typeofwater: { $in: ["drinking", "Drinking Water"] } }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
let filteredConsumptions;
|
|
|
|
|
if (start.getTime() === end.getTime()) {
|
|
|
|
|
// If start and end are the same, filter for exact match
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
return moment(record.time, "DD-MMM-YYYY - HH:mm").toDate().getTime() === start.getTime();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Normal range filter
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
const recordTime = moment(record.time, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
return recordTime >= start && recordTime <= end;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
|
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
|
}, 0);
|
|
|
|
|