made changes in start and stop,created consumption

master
varun 3 years ago
parent daaf44494d
commit d381d95533

@ -225,11 +225,6 @@ exports.updateTanklevels1 = 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;
@ -249,17 +244,7 @@ exports.getTanklevels = async (req, reply) => {
} }
}; };
const changingfrom_tankwaterlevel = async (customerId,initial_update,supplier_tank_info) => {
//console.log(customerId,"0")
//console.log(update_level,"1")
//console.log(fromSump,"2")
var result = await Tank.findOneAndUpdate(
{customerId:customerId, tankName: supplier_tank_info.tankName}, { $set: { waterlevel: initial_update } }
);
return result.waterlevel;
};
@ -277,10 +262,12 @@ exports.motorAction = async (req, reply) => {
supplier_tank_type = req.body.from_type supplier_tank_type = req.body.from_type
if(supplier_tank_type==="sump"){ if(supplier_tank_type==="sump"){
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank}); const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)-200;
await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info); //await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10) let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
intervalId = setInterval(async function () { intervalId = setInterval(async function () {
@ -306,13 +293,13 @@ exports.motorAction = async (req, reply) => {
} }
}, 2000); }, 2000);
} }
if(supplier_tank_type==="bore"){ if(supplier_tank_type==="bore"){
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2;
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank}); const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)-200;
await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10) let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
intervalId = setInterval(async function () { intervalId = setInterval(async function () {
@ -358,3 +345,27 @@ exports.motorAction = async (req, reply) => {
exports.consumption = async (req, reply) => {
try {
const customerId = req.params.customerId;
const tanks = await Tank.find({ customerId });
for (const tank of tanks) {
const tankId = tank._id;
let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
let waterLevel = capacity*2+1700; // initial water level
const newWaterLevel = Math.floor(waterLevel);
console.log(newWaterLevel);
}
return { message: 'Water level updates started' };
} catch (err) {
throw boom.boomify(err);
}
};

@ -248,6 +248,36 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.route({
method: "GET",
url: "/api/consumption/:customerId",
schema: {
tags: ["Tank"],
summary: "This is for getting consumption",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
// querystring: {
// tankName: {type: 'string'}
// },
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.consumption,
});
next(); next();
} }

Loading…
Cancel
Save