master^2
Bhaskar 5 months ago
parent 4483f5920f
commit 44a2699459

@ -610,11 +610,11 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
const isGSMConnected = diffInMinutes <= 1; const isGSMConnected = diffInMinutes <= 1;
const gsmStatus = isGSMConnected ? "connected" : "disconnected"; 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( await Insensors.findOneAndUpdate(
{ connected_to: hardwareId }, { hardwareId },
{ {
$set: { $set: {
connected_gsm_date, connected_gsm_date,
@ -622,11 +622,10 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
connected_status: gsmStatus, connected_status: gsmStatus,
gsm_last_check_time: gsmLastCheckTime 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 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");
@ -637,7 +636,6 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}; };
}); });
// ✅ Step 3: Response
return reply.send({ return reply.send({
status_code: 200, status_code: 200,
message: "Success", message: "Success",
@ -653,13 +651,13 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
time: latestRecord.time time: latestRecord.time
} }
}); });
} catch (err) { } catch (err) {
console.error("Error in getByHardwareId:", err); console.error("Error in getByHardwareId:", err);
return reply.status(500).send({ error: "Internal Server Error" }); return reply.status(500).send({ error: "Internal Server Error" });
} }
}; };
exports.getByHardwareIdSupport = async (req, reply) => { exports.getByHardwareIdSupport = async (req, reply) => {
try { try {
const { hardwareId } = req.params; const { hardwareId } = req.params;

Loading…
Cancel
Save