|
|
@ -114,17 +114,42 @@ 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' };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -132,6 +157,4 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|