working with water level

master
varun 3 years ago
parent aa82f20a11
commit 9f7eae7f95

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

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

Loading…
Cancel
Save