master
varun 1 year ago
parent 6811e2c38b
commit d02394b827

@ -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 });
}
};

@ -107,6 +107,7 @@ const motordataSchema = new mongoose.Schema({
receiverfinalwaterlevel: { type: String, default: "0" }, receiverfinalwaterlevel: { type: String, default: "0" },
startTime: { type: String, default: null }, startTime: { type: String, default: null },
stopTime: { type: String, default: null }, stopTime: { type: String, default: null },
runtime:{type:String, default:"0"},
supplier_type: { type: String, default: null }, supplier_type: { type: String, default: null },
receiver_type: { type: String, default: null }, receiver_type: { type: String, default: null },
quantity_delivered:{ type: String, default: null }, quantity_delivered:{ type: String, default: null },

@ -935,6 +935,36 @@ module.exports = function (fastify, opts, next) {
//preHandler: fastify.auth([fastify.authenticate]), //preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.update_auto_percentage, handler: tanksController.update_auto_percentage,
}); });
fastify.route({
method: "GET",
url: "/api/getBlockData/:customerId",
schema: {
tags: ["Tank"],
summary: "This is for get blocks under particular user",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
// querystring: {
// tankName: {type: 'string'}
// },
security: [
{
basicAuth: [],
},
],
},
//preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getBlockData,
});
next(); next();
} }

Loading…
Cancel
Save