diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index a2893398..9d35024b 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1290,6 +1290,30 @@ exports.getbatchnumbers = async (req, reply) => { }; +exports.getiots = async (req, reply) => { + try { + const storeId = req.params.storeId; + let type = req.params.type ? req.params.type.toUpperCase() : null; // Convert type to uppercase + + let query = { storeId: storeId }; + + if (type !== "ALL") { + query.type = type; + } + + // Fetch data based on the query + const result = await Insensors.find(query); + + if (!result ) { + return reply.send({ status_code: 404, error: "not found" }); + } + + reply.send({ status_code: 200, data: result }); + } catch (err) { + throw boom.boomify(err); + } +}; + exports.getusersofParticularInstaller = async (req, reply) => { try { await User.find({installationId: req.query.InstallerId}) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 794e7455..c5365f45 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -4659,6 +4659,8 @@ client.on('message', async (topic, message) => { time })); + + // Save IoT data for the received tanks const iotTankData = new IotData({ hardwareId: hw_Id, // Updated variable name @@ -4730,53 +4732,6 @@ client.on('message', async (topic, message) => { const inputConnection = motorTank.connections.inputConnections.find(conn => conn.motor_id === hw_Id); // Updated variable name if (inputConnection) { inputConnection.motor_status = status; // Update motor status - console.log(inputConnection.motor_stop_status,"inputConnection.motor_stop_status") - - if (inputConnection.motor_stop_status === "1" && status === "2") { - console.log("got into forced manual") - console.log(inputConnection.motor_on_type,"before if motor on type") - // Check if motor_on_type is not already "forced_manual" - if (inputConnection.motor_on_type !== "forced_manual") { - inputConnection.motor_on_type = "forced_manual"; - console.log("entered forced manual of if") - inputConnection.motor_stop_status = "2"; - // Update startTime to the current time in the specified format - const currentTime = new Date(); - const formattedTime = currentTime.toLocaleString('en-GB', { - day: '2-digit', - month: 'short', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - hour12: false, - }).replace(',', ''); - inputConnection.startTime = formattedTime; - } - } - - - if (inputConnection.motor_stop_status === "2" && status === "1") { - console.log("got into forced manual stop") - console.log(inputConnection.motor_on_type,"before if motor on type stop") - // Check if motor_on_type is not already "forced_manual" - if (inputConnection.motor_on_type = "forced_manual") { - inputConnection.motor_on_type = "manual"; - console.log("entered forced manual of if of stop") - - // Update startTime to the current time in the specified format - - - inputConnection.motor_stop_status = "1"; - } - } - - - - - - - - await motorTank.save(); // Save the updated tank } @@ -4789,6 +4744,8 @@ client.on('message', async (topic, message) => { }); + + // Function to publish motor stop status // exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { // const payload = { @@ -5038,5 +4995,5 @@ async function removeDuplicates() { } // Run the remove duplicates function -removeDuplicates(); +// removeDuplicates(); console.log("this is for testing autopush,line located in tankscontroller") \ No newline at end of file diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 50b48792..705ae5ac 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1138,6 +1138,35 @@ fastify.get("/api/getbatchnumbers/:storeId/:type", { handler: storeController.getbatchnumbers, }); +fastify.get("/api/getiots/:storeId/:type", { + schema: { + tags: ["Store-Data"], + description: "This is to Get iots of particular store", + summary: "This is to iots of particular store", + params: { + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + type: { + type: "string", + description: "type", + }, + }, + required: ["storeId", "type"], + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: storeController.getiots, +}); + fastify.post("/api/createquotationforSensor/:installationId", { schema: {