made changes in tanks controller

master
varun 3 years ago
parent 2b871d1114
commit af6892f8b1

@ -141,26 +141,34 @@ exports.getTank = async (req, reply) => {
// } // }
//}; //};
exports.updateTanklevels = async (req, reply) => { exports.updateTanklevels = async (req, reply) => {
try { try {
const customerId = req.params.customerId; const customerId = req.params.customerId;
const tank = await Tank.find({customerId}); const tank = await Tank.find({customerId});
for (var i=0; i < tank.length; i++) { for (var i=0; i < tank.length; i++) {
const tankname = tank[i].tankName const tankname = tank[i].tankName
const capacity = (tank[i].capacity).replace(/,/g, "") const capacity = (tank[i].capacity).replace(/,/g, "")
console.log(capacity) //console.log(capacity)
let Number = capacity-100 //Math.floor(Math.random() * capacity) let Number = capacity-100 //Math.floor(Math.random() * capacity)
//console.log(Number) //console.log(Number)
setInterval(async function () { setInterval(async function () {
// const randomNumber = Math.floor(Math.random() * capacity) // const randomNumber = Math.floor(Math.random() * capacity)
//const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);E //const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);
// console.log(randomNumber)
//console.log(tankname) //console.log(tankname)
const randomNumber = Math.floor(Number/1.5) const randomNumber = Math.floor(Number/1.5)
const data = await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname }, { $set: { waterlevel: randomNumber } });
const tank_info =await Tank.findOneAndUpdate({customerId:customerId,tankName:tankname},{$set:{waterlevel:randomNumber}})
console.log(tank_info)
Number = randomNumber Number = randomNumber
//return Number //return Number
@ -168,6 +176,9 @@ exports.updateTanklevels = async (req, reply) => {
}, 2000); }, 2000);
} }
return { message: 'Water level will be updated every 2 seconds' }; return { message: 'Water level will be updated every 2 seconds' };
} }
@ -177,6 +188,7 @@ exports.updateTanklevels = async (req, reply) => {
}; };
exports.getTanklevels = async (req, reply) => { exports.getTanklevels = async (req, reply) => {
try { try {
const customerId = req.params.customerId; const customerId = req.params.customerId;

@ -143,7 +143,7 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.route({ fastify.route({
method: "GET", method: "PUT",
url: "/api/updateTanklevels/:customerId", url: "/api/updateTanklevels/:customerId",
schema: { schema: {
tags: ["Tank"], tags: ["Tank"],

Loading…
Cancel
Save