working with water level

master
varun 3 years ago
parent aa82f20a11
commit 9f7eae7f95

@ -114,17 +114,42 @@ exports.getTank = async (req, reply) => {
throw boom.boomify(err);
}
};
//exports.getTanklevels = async (req, reply) => {
// try {
// const customerId = req.params.customerId;
// const tankName = req.query.tankName;
// setInterval(async function () {
// const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);
// console.log(randomNumber)
// console.log( await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankName }, { $set: { waterlevel: randomNumber } }));
// }, 2000);
// return { message: 'Water level will be updated every 2 seconds' };
//}
// catch (err) {
// throw boom.boomify(err);
// }
//};
exports.getTanklevels = async (req, reply) => {
try {
const customerId = req.params.customerId;
const tankName = req.query.tankName;
setInterval(async function () {
const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);
console.log(randomNumber)
console.log( await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankName }, { $set: { waterlevel: randomNumber } }));
}, 2000);
const tank = await Tank.find({customerId});
for (var i=0; i < tank.length; i++) {
const tankname = tank[i].tankName
const capacity = tank[i].capacity
//console.log(capacity)
setInterval(async function () {
const randomNumber = Math.floor(Math.random() * capacity)
//const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000);
// console.log(randomNumber)
console.log( await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname }, { $set: { waterlevel: randomNumber } }));
}, 2000);
}
return { message: 'Water level will be updated every 2 seconds' };
}
@ -132,6 +157,4 @@ exports.getTanklevels = async (req, reply) => {
throw boom.boomify(err);
}
};

@ -158,9 +158,9 @@ module.exports = function (fastify, opts, next) {
},
},
},
querystring: {
tankName: {type: 'string'}
},
// querystring: {
// tankName: {type: 'string'}
// },
security: [
{
basicAuth: [],

Loading…
Cancel
Save