|
|
|
@ -610,11 +610,11 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
const isGSMConnected = diffInMinutes <= 1;
|
|
|
|
|
const gsmStatus = isGSMConnected ? "connected" : "disconnected";
|
|
|
|
|
|
|
|
|
|
const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss"); // formatted current time
|
|
|
|
|
const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
// ✅ Step 1: Update Insensors with GSM date/time/status and last check time
|
|
|
|
|
// Update Insensors by hardwareId (corrected filter)
|
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
|
{ connected_to: hardwareId },
|
|
|
|
|
{ hardwareId },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
connected_gsm_date,
|
|
|
|
@ -622,11 +622,10 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
|
gsm_last_check_time: gsmLastCheckTime
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// ✅ Step 2: Annotate tanks with LoRa connection status based on tank date
|
|
|
|
|
// Annotate tanks with LoRa connection status based on tank date
|
|
|
|
|
const tanksWithConnectionStatus = latestRecord.tanks.map(tank => {
|
|
|
|
|
const tankMoment = moment.tz(tank.date, "Asia/Kolkata");
|
|
|
|
|
const tankDiff = now.diff(tankMoment, "minutes");
|
|
|
|
@ -637,7 +636,6 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ✅ Step 3: Response
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Success",
|
|
|
|
@ -653,13 +651,13 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
time: latestRecord.time
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error in getByHardwareId:", err);
|
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId } = req.params;
|
|
|
|
|