Updated package.json and fixed issues in controllers, models, and routes

master^2
ashok 1 year ago
parent c87c4b9678
commit 86a0e35b75

22350
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -40,7 +40,7 @@
"fastify-static": "^4.7.0",
"fastify-swagger": "^5.2.0",
"file-type": "^18.5.0",
"firebase-admin": "^12.4.0",
"firebase-admin": "^12.3.1",
"form-data": "^2.3.3",
"formidable": "^2.1.1",
"fs": "^0.0.1-security",
@ -62,7 +62,6 @@
"point-of-view": "^5.3.0",
"raw-body": "^2.4.1",
"request": "^2.88.2",
"stream-shift": "^1.0.3",
"twilio": "^2.5.2",
"urllib": "^2.38.0",
"xlsx": "^0.18.5",

@ -1359,6 +1359,8 @@ const sendNotification = async (fcmTokens, title, body) => {
// };
const stat_stop_intervals = {};
exports.motorAction = async (req, reply) => {
try {
const customerId = req.params.customerId;
@ -1395,6 +1397,11 @@ exports.motorAction = async (req, reply) => {
}
}
);
if (intervals[motorId]) {
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
console.log("interval cleared")
}
reply.code(200).send({ message: "Motor stopped successfully." });
@ -1480,7 +1487,8 @@ exports.motorAction = async (req, reply) => {
// Start monitoring water level based on threshold time
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
const intervalId = setInterval(async () => {
stat_stop_intervals[motorId] = setInterval(async () => {
console.log(stat_stop_intervals)
const splr_tank_info3 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
const splr_tank_info3_waterlevel = parseInt(splr_tank_info3.waterlevel, 10);
const splr_tank_info3_capacity = parseInt(splr_tank_info3.capacity.replace(/,/g, ''), 10);
@ -1498,7 +1506,9 @@ exports.motorAction = async (req, reply) => {
}
}
);
clearInterval(intervalId);
console.log(stat_stop_intervals[motorId])
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
// Send notification after motor stops due to time threshold
if (fcmToken) {
@ -1589,7 +1599,7 @@ exports.motorAction = async (req, reply) => {
}
// Start monitoring water level based on litres
const intervalId = setInterval(async () => {
stat_stop_intervals[motorId] = setInterval(async () => {
const supplier_tank_info1 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
const current_water_level = parseInt(supplier_tank_info1.waterlevel, 10);
if (current_water_level <= supplier_threshold) {
@ -1604,7 +1614,8 @@ exports.motorAction = async (req, reply) => {
}
}
);
clearInterval(intervalId);
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
await delay(300000);
@ -2738,8 +2749,7 @@ exports.IotDevice = async (req, reply) => {
};
exports.IotDeviceforstandalone = async (req, reply) => {
exports.IotDeviceforstandalonedevice = async (req, reply) => {
try {
const { hardwareId, Motor_status, tanks } = req.body;
@ -2762,7 +2772,7 @@ exports.IotDeviceforstandalone = async (req, reply) => {
// save the document to MongoDB
await ottank.save();
// Delete excess records (keep only the latest three records)
const recordsToKeep = 3;
const recordsToDelete = await IotData.find({ hardwareId })
@ -2856,7 +2866,6 @@ exports.IotDeviceforstandalone = async (req, reply) => {
// exports.IotDevice3 = async (req, reply) => {
// try {
// const { hardwareId, mode, tanks } = req.body;

@ -119,8 +119,8 @@ const motordataSchema = new mongoose.Schema({
const tankSchema = new mongoose.Schema({
tankhardwareId: { type: String },
tankHeight: { type: String, required: true },
maxLevel: { type: String, required: true },
minLevel: { type: String, required: true },
maxLevel: { type: String,default:null },
minLevel: { type: String,default:null },
date: { type: String, required: true },
time: { type: String, required: true }
});

@ -484,9 +484,45 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "POST",
url: "/api/APIWriteforstandalone",
schema: {
tags: ["Tank"],
description: "This is for creating an IOT Device for slave integrated in master",
summary: "this is to Create IOT Device for slave integrated in master",
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
Motor_status: { type: "string" },
tanks: {
type: "array",
items: {
type: "object",
properties: {
tankhardwareId: { type: "string" },
tankHeight: { type: "string" }
},
required: ["tankhardwareId", "tankHeight"]
}
}
},
required: ["hardwareId", "Motor_status", "tanks"]
},
security: [
{
basicAuth: []
}
]
},
handler: tanksController.IotDeviceforstandalonedevice
});
fastify.get("/api/APIRead", {

Loading…
Cancel
Save