ashok 1 year ago
commit f95e887dd4

@ -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,
@ -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;
@ -571,6 +597,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 +635,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 = {

@ -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 = [];

@ -155,8 +155,9 @@ const installationschema = new mongoose.Schema({
},
updatedBy: ObjectId,
}, { versionKey: false });
module.exports = mongoose.model('Store', storeSchema);

@ -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",
@ -212,6 +243,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", {

Loading…
Cancel
Save