|
|
|
@ -11,6 +11,16 @@ const cron = require('node-cron');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function deleteOldRecords() {
|
|
|
|
|
const SEVEN_DAYS_IN_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
|
const sevenDaysAgo = new Date(Date.now() - SEVEN_DAYS_IN_MILLISECONDS);
|
|
|
|
|
|
|
|
|
|
await MotorData.deleteMany({ startTime: { $lt: sevenDaysAgo } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addTanks = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
@ -250,11 +260,11 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const intervals = {};
|
|
|
|
|
|
|
|
|
|
let start_time=""
|
|
|
|
|
|
|
|
|
|
exports.motorAction = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
let start_time,stop_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const action = req.body.action
|
|
|
|
@ -271,6 +281,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
if(action === "start"){
|
|
|
|
|
start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
console.log(start_time)
|
|
|
|
|
// const stop_at = req.body.stop_at
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -582,6 +593,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
const allMotorStatusZero = tankToUpdate.connections.inputConnections.every(connection => connection.motor_status === "0");
|
|
|
|
|
|
|
|
|
|
if (allMotorStatusZero) {
|
|
|
|
|
console.log(allMotorStatusZero)
|
|
|
|
|
// Update the motor_status field to "0" for the tank
|
|
|
|
|
await Tank.findOneAndUpdate(
|
|
|
|
|
{ customerId, tankName: receiver_tank, tankLocation: receiver_type },
|
|
|
|
@ -598,8 +610,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
supplier_type: supplier_tank_type,
|
|
|
|
|
receiverTank: receiver_tank,
|
|
|
|
|
receiver_type: receiver_type,
|
|
|
|
|
// startTime: startTime,
|
|
|
|
|
stopTime: req.body.stopTime,
|
|
|
|
|
startTime: start_time,
|
|
|
|
|
stopTime: stop_time,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -615,7 +627,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
motorData.receiverTank = receiver_tank;
|
|
|
|
|
motorData.supplier_type = supplier_type;
|
|
|
|
|
motorData.receiver_type = receiver_type;
|
|
|
|
|
//motorData.startTime = startTime;
|
|
|
|
|
motorData.startTime = start_time;
|
|
|
|
|
motorData.stopTime = stop_time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1065,3 +1077,26 @@ exports.updatewaterlevelsatmidnight = async (req, reply) => {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deletemotordatarecordsbefore7days = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
// Schedule the task to run every day at 10 seconds past the minute
|
|
|
|
|
cron.schedule('0 0 * * *', async () => {
|
|
|
|
|
try {
|
|
|
|
|
// Run the deletion task once a day
|
|
|
|
|
setInterval(async () => {
|
|
|
|
|
await deleteOldRecords();
|
|
|
|
|
}, 24 * 60 * 60 * 1000); // 24 hours in milliseconds
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error occurred:', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|