made changes in tanks controller

master
varun 3 years ago
parent 27bd372904
commit ce802ed7bd

@ -145,27 +145,25 @@ 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});
clearInterval(intervalTimer);
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 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); //const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);E
// console.log(randomNumber)
//console.log(tankname) //console.log(tankname)
const randomNumber = Math.floor(Number/1.5) const randomNumber = Math.floor(Number/1.5)
console.log(randomNumber) const data = await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname }, { $set: { waterlevel: randomNumber } });
await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname },{ $set: { waterlevel: randomNumber } }, { upsert: true, new: true });
Number = randomNumber Number = randomNumber
//return Number // return Number
}, 2000); }, 2000);
} }
@ -182,7 +180,6 @@ 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;
// await tanksController.updateTanklevels(req)
const updated_data = await Tank.find({ customerId: customerId }); const updated_data = await Tank.find({ customerId: customerId });
@ -198,4 +195,4 @@ exports.getTanklevels = async (req, reply) => {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
Loading…
Cancel
Save