From 9fb34945e9cd31a417e30d6105dfcd88d63b7f13 Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 11 Jul 2024 02:04:53 -0400 Subject: [PATCH 1/3] added bulding name in get tank levels --- src/controllers/tanksController.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index cfcd6dcc..14afdab7 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1,7 +1,7 @@ //const Tank = require("../models/tanks"); const { Tank, MotorData, IotData,MotorIot,TankWaterLevel,TankConsumptionSchema } = require('../models/tanks') -const User = require("../models/User"); +const {User} = require("../models/User"); const boom = require("boom"); const fastify = require("fastify")({ logger: true, @@ -339,6 +339,10 @@ exports.getTanklevels = async (req, reply) => { } }); + const user = await User.findOne({ customerId: customerId }); + const buildingName = user ? user.buildingName : null; + const address1 = user ? user.profile.address1 : null; + const responseData = { status_code: 200, data: updated_data, @@ -350,6 +354,8 @@ exports.getTanklevels = async (req, reply) => { totalDrinkingWaterInOverheadCapacity: sumOverheadDrinkingWaterCapacity, totalBoreWaterInSumpCapacity: sumSumpBoreWaterCapacity, totalBoreWaterInOverheadCapacity: sumOverheadBoreWaterCapacity, + buildingName: buildingName, + address1: address1, }; if (!reply.sent) { @@ -366,6 +372,7 @@ exports.getTanklevels = async (req, reply) => { + const intervals = {}; let sump_water_levels=[]; let supplier_tanks = []; From 5caf396cb00b5a0e8b359355a35d41a0a22e3abb Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 11 Jul 2024 02:21:01 -0400 Subject: [PATCH 2/3] get for quality check --- src/controllers/storeController.js | 20 +++++++++++++++++-- src/models/store.js | 3 ++- src/routes/storeRoute.js | 31 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index af81da60..4bee54ad 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -513,7 +513,7 @@ exports.addStore = async (request, reply) => { const { hardwareId,hardwareId_company, type, indate } = req.body; var mater_seq_id = await generatewaterlevelsensorId(); const date = moment().format('MM-DD'); - const prefix = 'AS-' + date + '--MALOV1-'; + const prefix = 'AS' + date + 'MALOV1-'; var masterId = `${prefix}${mater_seq_id}`; const newSensor = new WaterLeverSensor({ storeId, @@ -571,6 +571,22 @@ exports.addStore = async (request, reply) => { }; + exports.getHardwareqc = async (req, reply) => { + try { + await WaterLeverSensor.find({storeId: req.params.storeId,hardwareId:req.body.hardwareId}) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + throw boom.boomify(err); + } + }; + exports.addSlave = async (req, reply) => { try { const hardwareId = req.params.hardwareId; @@ -593,7 +609,7 @@ exports.addStore = async (request, reply) => { } var slave_seq_id = await generatewaterlevelslavesensorId(); const date = moment().format('MM-DD'); - const prefix = 'AS-' + date + '--SLAOV1-'; + const prefix = 'AS' + date + 'SLAOV1-'; var slaveId = `${prefix}${slave_seq_id}`; // Create new slave const newSlave = { diff --git a/src/models/store.js b/src/models/store.js index d0be8415..f2c8e192 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -155,8 +155,9 @@ const installationschema = new mongoose.Schema({ }, updatedBy: ObjectId, }, { versionKey: false }); + + - module.exports = mongoose.model('Store', storeSchema); diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index ed56109c..8c20d21f 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -212,6 +212,37 @@ fastify.get("/api/getHardware/:storeId", { handler: storeController.getHardware, }); +fastify.put("/api/getHardwareqc/:storeId", { + schema: { + tags: ["Store-Data"], + description: "This is to Get Quality Check Hardware Data", + summary: "This is to Get Quality Check Hardware Data", + params: { + required: ["storeId"], + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + }, + }, + body: { + type: "object", + properties: { + hardwareId: { type: "string" }, + + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: storeController.getHardwareqc, +}); fastify.post("/api/addSlave/:hardwareId", { From 937570b4b656475b5354e613306c3b36d0d1a576 Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 11 Jul 2024 02:31:00 -0400 Subject: [PATCH 3/3] Installing master --- src/controllers/storeController.js | 28 ++++++++++++++++++++++++++- src/routes/storeRoute.js | 31 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 4bee54ad..9a7b5f56 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -529,7 +529,33 @@ exports.addStore = async (request, reply) => { } }; - + + + + + exports.installwaterlevelSensor = async (request, reply) => { + try { + const { storeId } = request.params; + const updateData = request.body; + + // Find the document by hardwareId and update it with the fields received in the body + const updatedSensor = await WaterLeverSensor.findOneAndUpdate( + { storeId:storeId,hardwareId: request.body.hardwareId, }, + { $set: updateData }, + { new: true } // Return the updated document + ); + + if (!updatedSensor) { + return reply.status(404).send({ error: 'Sensor not found' }); + } + + return reply.status(200).send(updatedSensor); + } catch (error) { + console.error(error); + return reply.status(500).send({ error: 'An error occurred while updating the sensor' }); + } + }; + exports.qccheckwaterlevelSensor = async (request, reply) => { try { const { hardwareId } = request.params; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 8c20d21f..6c4346b6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -154,6 +154,37 @@ fastify.post("/api/createwaterlevelSensor/:storeId", { handler: storeController.createwaterlevelSensor, }) +fastify.post("/api/installwaterlevelSensor/:storeId", { + schema: { + description: "This is for installing waterlevel Sensor", + tags: ["Store-Data"], + summary: "This is for installing waterlevel Sensor", + params: { + required: ["storeId"], + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + }, + }, + + body: { + type: "object", + + properties: { + + hardwareId: { type: "string" }, + dateofinstallation: { type: "string" }, + customerId: { type: "string" }, + installedby: { type: "string" } + }, + }, + }, + handler: storeController.installwaterlevelSensor, +}) + fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", { schema: { description: "This is for checking waterlevel Sensor",