|
|
@ -690,8 +690,8 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss"); // formatted current time
|
|
|
|
const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss"); // formatted current time
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Step 1: Update Insensors with GSM date/time/status and last check time
|
|
|
|
// ✅ Update slaves connected to this master hardwareId
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
await Insensors.updateMany(
|
|
|
|
{ connected_to: hardwareId },
|
|
|
|
{ connected_to: hardwareId },
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
$set: {
|
|
|
@ -700,11 +700,23 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
support_gsm_last_check_time: gsmLastCheckTime
|
|
|
|
support_gsm_last_check_time: gsmLastCheckTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
{ new: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Update the master device itself (if it's a master)
|
|
|
|
|
|
|
|
await Insensors.updateOne(
|
|
|
|
|
|
|
|
{ hardwareId },
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$set: {
|
|
|
|
|
|
|
|
connected_gsm_date,
|
|
|
|
|
|
|
|
connected_gsm_time,
|
|
|
|
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
|
|
|
|
support_gsm_last_check_time: gsmLastCheckTime
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Step 2: Annotate tanks with LoRa connection status based on tank date
|
|
|
|
// ✅ Annotate tanks with LoRa connection status
|
|
|
|
const tanksWithConnectionStatus = latestRecord.tanks.map(tank => {
|
|
|
|
const tanksWithConnectionStatus = latestRecord.tanks.map(tank => {
|
|
|
|
const tankMoment = moment.tz(tank.date, "Asia/Kolkata");
|
|
|
|
const tankMoment = moment.tz(tank.date, "Asia/Kolkata");
|
|
|
|
const tankDiff = now.diff(tankMoment, "minutes");
|
|
|
|
const tankDiff = now.diff(tankMoment, "minutes");
|
|
|
@ -715,7 +727,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Step 3: Response
|
|
|
|
// ✅ Response
|
|
|
|
return reply.send({
|
|
|
|
return reply.send({
|
|
|
|
status_code: 200,
|
|
|
|
status_code: 200,
|
|
|
|
message: "Success",
|
|
|
|
message: "Success",
|
|
|
@ -733,7 +745,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error in getByHardwareId:", err);
|
|
|
|
console.error("Error in getByHardwareIdSupport:", err);
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -879,7 +891,7 @@ exports.getByHardwareAndTankIdSupport = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
let connected_lora_date = null;
|
|
|
|
let connected_lora_date = null;
|
|
|
|
let connected_lora_time = null;
|
|
|
|
let connected_lora_time = null;
|
|
|
|
let support_lora_last_check_time = null;
|
|
|
|
let support_lora_last_check_time = moment.tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
if (isLoraConnected) {
|
|
|
|
if (isLoraConnected) {
|
|
|
|
connected_lora_date = formattedDate;
|
|
|
|
connected_lora_date = formattedDate;
|
|
|
@ -888,15 +900,24 @@ exports.getByHardwareAndTankIdSupport = async (req, reply) => {
|
|
|
|
updateFields.connected_lora_time = connected_lora_time;
|
|
|
|
updateFields.connected_lora_time = connected_lora_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Format LoRa last check time in "YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
|
|
|
support_lora_last_check_time = moment.tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
|
|
|
updateFields.support_lora_last_check_time = support_lora_last_check_time;
|
|
|
|
updateFields.support_lora_last_check_time = support_lora_last_check_time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 🔍 Add debugging to check if the document exists
|
|
|
|
|
|
|
|
const sensorToUpdate = await Insensors.findOne({
|
|
|
|
|
|
|
|
connected_to: hardwareId,
|
|
|
|
|
|
|
|
hardwareId: tankhardwareId
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sensorToUpdate) {
|
|
|
|
|
|
|
|
console.warn("No matching Insensors document found for update");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
{ connected_to: hardwareId, hardwareId: tankhardwareId },
|
|
|
|
{ connected_to: hardwareId, hardwareId: tankhardwareId },
|
|
|
|
{ $set: updateFields },
|
|
|
|
{ $set: { ...updateFields, support_lora_last_check_time } },
|
|
|
|
{ new: true }
|
|
|
|
{ new: true }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const displayMessage = isLoraConnected ? "LoRa connected" : "LoRa not connected";
|
|
|
|
const displayMessage = isLoraConnected ? "LoRa connected" : "LoRa not connected";
|
|
|
|
|
|
|
|
|
|
|
@ -907,10 +928,11 @@ exports.getByHardwareAndTankIdSupport = async (req, reply) => {
|
|
|
|
lora_connected_status: updateFields.connected_status,
|
|
|
|
lora_connected_status: updateFields.connected_status,
|
|
|
|
connected_lora_date,
|
|
|
|
connected_lora_date,
|
|
|
|
connected_lora_time,
|
|
|
|
connected_lora_time,
|
|
|
|
support_lora_last_check_time });
|
|
|
|
support_lora_last_check_time
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error in getByHardwareAndTankId:", err);
|
|
|
|
console.error("Error in getByHardwareAndTankIdSupport:", err);
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -3673,7 +3695,7 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("order",orderMap)
|
|
|
|
const masterMap = {};
|
|
|
|
const masterMap = {};
|
|
|
|
|
|
|
|
|
|
|
|
for (const issue of allIssues) {
|
|
|
|
for (const issue of allIssues) {
|
|
|
@ -3704,6 +3726,7 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const master = masterMap[masterSensor.hardwareId];
|
|
|
|
const master = masterMap[masterSensor.hardwareId];
|
|
|
|
|
|
|
|
console.log("master",master)
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Always fetch slaves using connected_to
|
|
|
|
// ✅ Always fetch slaves using connected_to
|
|
|
|
const connectedSlaves = await Insensors.find({
|
|
|
|
const connectedSlaves = await Insensors.find({
|
|
|
|