ashok 7 months ago
commit 0d4672ef0d

@ -578,6 +578,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
} }
}; };
// const moment = require('moment-timezone');
exports.getByHardwareId = async (req, reply) => { exports.getByHardwareId = async (req, reply) => {
try { try {
@ -604,20 +605,25 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
const connected_gsm_date = indiaTime.format("YYYY-MM-DD"); const connected_gsm_date = indiaTime.format("YYYY-MM-DD");
const connected_gsm_time = indiaTime.format("HH:mm:ss"); const connected_gsm_time = indiaTime.format("HH:mm:ss");
// Step 1: Update connected_gsm fields in Insensors const now = moment.tz("Asia/Kolkata");
const diffInMinutes = now.diff(indiaTime, "minutes");
const isGSMConnected = diffInMinutes <= 1;
const gsmStatus = isGSMConnected ? "connected" : "disconnected";
// ✅ Step 1: Update Insensors with GSM date/time/status
await Insensors.findOneAndUpdate( await Insensors.findOneAndUpdate(
{ connected_to: hardwareId }, { connected_to: hardwareId },
{ $set: { connected_gsm_date, connected_gsm_time } }, {
$set: {
connected_gsm_date,
connected_gsm_time,
connected_status: gsmStatus
}
},
{ new: true } { new: true }
); );
// Step 2: Check GSM Connection - compare now with latestRecord.date // ✅ Step 2: Annotate tanks with LoRa connection status based on tank date
const now = moment.tz("Asia/Kolkata");
const diffInMinutes = now.diff(indiaTime, "minutes");
const isGSMConnected = diffInMinutes <= 1;
const gsmConnectionMessage = isGSMConnected ? "GSM Connected" : "GSM Not Connected";
// Step 3: Optional - Annotate each tank with 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");
@ -628,13 +634,14 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}; };
}); });
// Step 4: Return result // ✅ Step 3: Response
return reply.send({ return reply.send({
status_code: 200, status_code: 200,
message: "Success", message: "Success",
data: { data: {
hardwareId, hardwareId,
gsmStatus: gsmConnectionMessage, connected_status: gsmStatus,
gsmStatus: isGSMConnected ? "GSM Connected" : "GSM Not Connected",
connected_gsm_date, connected_gsm_date,
connected_gsm_time, connected_gsm_time,
tanks: tanksWithConnectionStatus, tanks: tanksWithConnectionStatus,

Loading…
Cancel
Save