ashok 6 months ago
commit 0d4672ef0d

@ -578,6 +578,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}
};
// const moment = require('moment-timezone');
exports.getByHardwareId = async (req, reply) => {
try {
@ -604,20 +605,25 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
const connected_gsm_date = indiaTime.format("YYYY-MM-DD");
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(
{ connected_to: hardwareId },
{ $set: { connected_gsm_date, connected_gsm_time } },
{
$set: {
connected_gsm_date,
connected_gsm_time,
connected_status: gsmStatus
}
},
{ new: true }
);
// Step 2: Check GSM Connection - compare now with latestRecord.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
// ✅ Step 2: 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");
@ -628,13 +634,14 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
};
});
// Step 4: Return result
// ✅ Step 3: Response
return reply.send({
status_code: 200,
message: "Success",
data: {
hardwareId,
gsmStatus: gsmConnectionMessage,
connected_status: gsmStatus,
gsmStatus: isGSMConnected ? "GSM Connected" : "GSM Not Connected",
connected_gsm_date,
connected_gsm_time,
tanks: tanksWithConnectionStatus,

Loading…
Cancel
Save