|
|
@ -1,6 +1,5 @@
|
|
|
|
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
|
|
|
|
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
|
|
|
|
const { Tank } = require('../models/tanks')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { FriendRequest } = require('../models/supplier')
|
|
|
|
const { FriendRequest } = require('../models/supplier')
|
|
|
|
//const User = require("../models/User");
|
|
|
|
//const User = require("../models/User");
|
|
|
@ -19,7 +18,7 @@ exports.addTankers = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
//const username = req.params.username;
|
|
|
|
//const username = req.params.username;
|
|
|
|
|
|
|
|
|
|
|
|
console.log(req.params);
|
|
|
|
console.log(req.params);
|
|
|
|
const supplierId = req.params.supplierId;
|
|
|
|
const supplierId = req.params.supplierId;
|
|
|
|
//console.log(loginObject.user.username)
|
|
|
|
//console.log(loginObject.user.username)
|
|
|
|
// const userInfo = await User.findOne({ username: username.toString() });
|
|
|
|
// const userInfo = await User.findOne({ username: username.toString() });
|
|
|
@ -194,8 +193,6 @@ exports.tankerBooking = async (req, reply) => {
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
bookingsData = {
|
|
|
|
bookingsData = {
|
|
|
|
tankname:req.body.tankname,
|
|
|
|
|
|
|
|
tankLocation:req.body.tankLocation,
|
|
|
|
|
|
|
|
tankerName:tankerName,
|
|
|
|
tankerName:tankerName,
|
|
|
|
customerId:customerId,
|
|
|
|
customerId:customerId,
|
|
|
|
bookingid : bookingId,
|
|
|
|
bookingid : bookingId,
|
|
|
@ -203,6 +200,8 @@ exports.tankerBooking = async (req, reply) => {
|
|
|
|
capacity: req.body.capacity,
|
|
|
|
capacity: req.body.capacity,
|
|
|
|
address: req.body.address,
|
|
|
|
address: req.body.address,
|
|
|
|
dateOfOrder: req.body.dateOfOrder,
|
|
|
|
dateOfOrder: req.body.dateOfOrder,
|
|
|
|
|
|
|
|
price:req.body.price,
|
|
|
|
|
|
|
|
supplierId:req.body.supplierId
|
|
|
|
//date: req.body.date,
|
|
|
|
//date: req.body.date,
|
|
|
|
// time: req.body.time,
|
|
|
|
// time: req.body.time,
|
|
|
|
|
|
|
|
|
|
|
@ -215,14 +214,14 @@ exports.tankerBooking = async (req, reply) => {
|
|
|
|
usertobeInserted = checkFormEncoding.tankersBookingData;
|
|
|
|
usertobeInserted = checkFormEncoding.tankersBookingData;
|
|
|
|
console.log("thsi true url string");
|
|
|
|
console.log("thsi true url string");
|
|
|
|
tankersBookingData.customerId = customerId;
|
|
|
|
tankersBookingData.customerId = customerId;
|
|
|
|
tankersBookingData.tankname = usertobeInserted.tankname;
|
|
|
|
|
|
|
|
tankersBookingData.tankLocation = usertobeInserted.tankLocation;
|
|
|
|
|
|
|
|
tankersBookingData.tankerName = tankerName;
|
|
|
|
tankersBookingData.tankerName = tankerName;
|
|
|
|
tankersBookingData.bookingid = bookingId;
|
|
|
|
tankersBookingData.bookingid = bookingId;
|
|
|
|
tankersBookingData.capacity = usertobeInserted.capacity;
|
|
|
|
tankersBookingData.capacity = usertobeInserted.capacity;
|
|
|
|
tankersBookingData.typeofwater = usertobeInserted.typeofwater;
|
|
|
|
tankersBookingData.typeofwater = usertobeInserted.typeofwater;
|
|
|
|
tankersBookingData.address = usertobeInserted.address;
|
|
|
|
tankersBookingData.address = usertobeInserted.address;
|
|
|
|
tankersBookingData.dateOfOrder = usertobeInserted.dateOfOrder;
|
|
|
|
tankersBookingData.dateOfOrder = usertobeInserted.dateOfOrder;
|
|
|
|
|
|
|
|
tankersBookingData.price = usertobeInserted.price;
|
|
|
|
|
|
|
|
tankersBookingData.supplierId = usertobeInserted.supplierId;
|
|
|
|
//tankersBookingData.date = usertobeInserted.date;
|
|
|
|
//tankersBookingData.date = usertobeInserted.date;
|
|
|
|
//tankersBookingData.time = usertobeInserted.time;
|
|
|
|
//tankersBookingData.time = usertobeInserted.time;
|
|
|
|
|
|
|
|
|
|
|
@ -305,6 +304,54 @@ exports.getTankersBookingdetails = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getAllTankersBookingdetails = async (req, reply) => {
|
|
|
|
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
|
|
|
|
const supplierId = req.params.supplierId
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await Tankerbooking.find( { supplierId:supplierId })
|
|
|
|
|
|
|
|
.limit(limit)
|
|
|
|
|
|
|
|
.skip(startindex)
|
|
|
|
|
|
|
|
.exec()
|
|
|
|
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getAllTankersaccepted = async (req, reply) => {
|
|
|
|
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
|
|
|
|
const supplierId = req.params.supplierId
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await Tankerbooking.find( { supplierId, orderStatus: ["accepted","rejected"] })
|
|
|
|
|
|
|
|
.limit(limit)
|
|
|
|
|
|
|
|
.skip(startindex)
|
|
|
|
|
|
|
|
.exec()
|
|
|
|
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addBores = async (req, reply) => {
|
|
|
|
exports.addBores = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -587,214 +634,3 @@ exports.connectstatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deliveryboystart = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//let start_time,stop_time
|
|
|
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
const tankLocation = req.body.tankLocation;
|
|
|
|
|
|
|
|
const action = req.body.action
|
|
|
|
|
|
|
|
const receiver_tank = req.body.tankname
|
|
|
|
|
|
|
|
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:tankLocation.toLowerCase()});
|
|
|
|
|
|
|
|
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
const intervals = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(action === "start"){
|
|
|
|
|
|
|
|
start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const supplier_tank = req.body.from
|
|
|
|
|
|
|
|
const supplier_tank_type = (req.body.from_type).toLowerCase()
|
|
|
|
|
|
|
|
const receiver_type = (req.body.to_type).toLowerCase()
|
|
|
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "1" } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
|
|
|
//console.log(supplier_tank_info1)
|
|
|
|
|
|
|
|
//const initial_update = parseInt(supplier_tank_info1.waterlevel.replace(/,/g, ''), 10)-200;
|
|
|
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
|
|
|
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// console.log(supplier_waterlevel)
|
|
|
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
intervals[receiver_tank] = setInterval(async function () {
|
|
|
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
|
|
|
const supplier_tank_info2 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
|
|
|
|
|
|
|
|
const newWaterLevel = receiver_waterlevel + 350//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
|
|
|
const newSupplierWaterLevel = supplier_waterlevel//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
|
|
|
const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
|
|
|
// Check if updating should stop
|
|
|
|
|
|
|
|
if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0") {
|
|
|
|
|
|
|
|
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
|
|
|
|
|
|
|
|
delete intervals[receiver_tank];
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("end for"+receiver_tank);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
|
|
|
//supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
|
|
|
console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
|
|
|
// console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
|
|
|
console.log(receiver_tank+""+newWaterLevel+""+"bore to sump")
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } })
|
|
|
|
|
|
|
|
if (supplier_tank_info2.motor_status==="0"){
|
|
|
|
|
|
|
|
supplier_waterlevel = parseInt(supplier_tank_info2.waterlevel.replace(/,/g, ''), 10)-350
|
|
|
|
|
|
|
|
console.log(supplier_tank+""+newSupplierWaterLevel+""+"s to oh")
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: supplier_waterlevel } })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // console.log(rcvr_info.motor_status)
|
|
|
|
|
|
|
|
// 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});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// intervalId = setInterval(async function () {
|
|
|
|
|
|
|
|
// const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank});
|
|
|
|
|
|
|
|
// const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// // Calculate new water levels
|
|
|
|
|
|
|
|
// const newWaterLevel = receiver_waterlevel + 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
|
|
|
// const newSupplierWaterLevel = Math.min(supplier_capacity, supplier_waterlevel + 350);// Math.floor(supplier_waterlevel * 0.15));
|
|
|
|
|
|
|
|
// // console.log(newWaterLevel)
|
|
|
|
|
|
|
|
// // console.log(newSupplierWaterLevel)
|
|
|
|
|
|
|
|
// // console.log(rcvr_info.motor_status)
|
|
|
|
|
|
|
|
// // console.log(rcvr_info.tankName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Check if updating should stop
|
|
|
|
|
|
|
|
// if ( (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clearInterval(intervalId)
|
|
|
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("end");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// // Update water levels in database
|
|
|
|
|
|
|
|
// supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
|
|
|
// receiver_waterlevel = newWaterLevel;
|
|
|
|
|
|
|
|
// // console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
|
|
|
// // console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
|
|
|
// await Promise.all([
|
|
|
|
|
|
|
|
// Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
|
|
|
// Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: newSupplierWaterLevel } })
|
|
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
|
|
|
|
const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// console.log(receiver_capacity,"0",receiver_tank_info.tankName)
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "1" } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
// console.log(receiver_waterlevel,"1")
|
|
|
|
|
|
|
|
intervals[receiver_tank] = setInterval(async function () {
|
|
|
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
|
|
|
|
|
|
|
|
//console.log(rcvr_info)
|
|
|
|
|
|
|
|
//console.log(rcvr_info.motor_status)
|
|
|
|
|
|
|
|
const newWaterLevel = receiver_waterlevel+450;
|
|
|
|
|
|
|
|
//console.log(newWaterLevel,"2",receiver_tank_info.tankName)
|
|
|
|
|
|
|
|
// Check if updating should stop
|
|
|
|
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } });
|
|
|
|
|
|
|
|
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
|
|
|
|
|
|
|
|
delete intervals[receiver_tank];
|
|
|
|
|
|
|
|
console.log("end for" + receiver_tank);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
|
|
|
console.log(receiver_tank+""+newWaterLevel+""+"bore to sump")
|
|
|
|
|
|
|
|
//console.log((newWaterLevel/receiver_capacity)*100,"4",receiver_tank_info.tankName)
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,)
|
|
|
|
|
|
|
|
motorData = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
customerId:customerId,
|
|
|
|
|
|
|
|
supplierTank : req.body.from,
|
|
|
|
|
|
|
|
supplier_type: req.body.from_type,
|
|
|
|
|
|
|
|
receiverTank: receiver_tank,
|
|
|
|
|
|
|
|
receiver_type: req.body.to_type,
|
|
|
|
|
|
|
|
startTime: req.body.startTime,
|
|
|
|
|
|
|
|
stopTime: req.body.stopTime,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var motorData = new MotorData(motorData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkFormEncoding = isUserFormUrlEncoded(req);
|
|
|
|
|
|
|
|
if (checkFormEncoding.isUserFormUrlEncoded) {
|
|
|
|
|
|
|
|
usertobeInserted = checkFormEncoding.motorData;
|
|
|
|
|
|
|
|
console.log("thsi true url string");
|
|
|
|
|
|
|
|
motorData.customerId = customerId;
|
|
|
|
|
|
|
|
motorData.supplierTank = req.body.from;
|
|
|
|
|
|
|
|
motorData.receiverTank = receiver_tank;
|
|
|
|
|
|
|
|
motorData.supplier_type = req.body.from_type;
|
|
|
|
|
|
|
|
motorData.receiver_type = req.body.to_type;
|
|
|
|
|
|
|
|
motorData.startTime = usertobeInserted.startTime;
|
|
|
|
|
|
|
|
motorData.stopTime = usertobeInserted.stopTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const motor_data = await motorData.save();
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, data: motor_data });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, "start time": start_time, data: motor_data});
|
|
|
|
|
|
|
|
console.log(start_time)
|
|
|
|
|
|
|
|
return motor_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (action === "stop") {
|
|
|
|
|
|
|
|
stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
|
|
|
// console.log(stop_time)
|
|
|
|
|
|
|
|
// clearInterval(intervalId);
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, "stop time": stop_time});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new Error("Invalid action");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'Water level updates started' };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw new Error(`Failed to start/stop water level updates: ${err.message}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|