|
|
@ -942,15 +942,17 @@ let supplier_tanks = [];
|
|
|
|
exports.consumption = async (request, reply) => {
|
|
|
|
exports.consumption = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { startDate, stopDate, block, typeofwater } = request.body;
|
|
|
|
const { startDate, stopDate, block } = req.body;
|
|
|
|
|
|
|
|
let { typeofwater } = req.body;
|
|
|
|
|
|
|
|
// Convert typeofwater to lowercase
|
|
|
|
|
|
|
|
typeofwater = typeofwater.toLowerCase();
|
|
|
|
const start = startDate;
|
|
|
|
const start = startDate;
|
|
|
|
const end = stopDate;
|
|
|
|
const end = stopDate;
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
|
|
|
|
|
|
|
|
|
if (block !== "all") {
|
|
|
|
if (block !== "All") {
|
|
|
|
tankQuery.blockName = block; // Filter by specific block if not "all"
|
|
|
|
tankQuery.blockName = block; // Filter by specific block if not "all"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -975,7 +977,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
$gte: start,
|
|
|
|
$gte: start,
|
|
|
|
$lte: end
|
|
|
|
$lte: end
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...(block !== "all" && { block: tank.blockName }), // Ensure correct field names
|
|
|
|
...(block !== "All" && { block: tank.blockName }), // Ensure correct field names
|
|
|
|
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater }) // Ensure correct field names
|
|
|
|
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater }) // Ensure correct field names
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -3131,4 +3133,27 @@ setInterval(storeWaterLevels, 15 * 60 * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Cron job scheduled to update water levels at midnight');
|
|
|
|
console.log('Cron job scheduled to update water levels at midnight');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getBlockData = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get all tank documents for the current customerId
|
|
|
|
|
|
|
|
const tanks = await Tank.find({ customerId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extract the blockName from each tank
|
|
|
|
|
|
|
|
const blockNames = tanks.map(tank => tank.blockName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove duplicates by converting the array to a Set and then back to an array
|
|
|
|
|
|
|
|
const uniqueBlockNames = [...new Set(blockNames)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send the unique blockNames in the response
|
|
|
|
|
|
|
|
reply.code(200).send({ blockNames: uniqueBlockNames });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
// Send an error response
|
|
|
|
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|