|
|
|
@ -610,14 +610,17 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
const isGSMConnected = diffInMinutes <= 1;
|
|
|
|
|
const gsmStatus = isGSMConnected ? "connected" : "disconnected";
|
|
|
|
|
|
|
|
|
|
// ✅ Step 1: Update Insensors with GSM date/time/status
|
|
|
|
|
const gsmLastCheckTime = now.format("YYYY-MM-DD HH:mm:ss"); // formatted current time
|
|
|
|
|
|
|
|
|
|
// ✅ Step 1: Update Insensors with GSM date/time/status and last check time
|
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
|
{ connected_to: hardwareId },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
connected_gsm_date,
|
|
|
|
|
connected_gsm_time,
|
|
|
|
|
connected_status: gsmStatus
|
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
|
gsm_last_check_time: gsmLastCheckTime
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
@ -644,9 +647,10 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
gsmStatus: isGSMConnected ? "GSM Connected" : "GSM Not Connected",
|
|
|
|
|
connected_gsm_date,
|
|
|
|
|
connected_gsm_time,
|
|
|
|
|
gsm_last_check_time: gsmLastCheckTime,
|
|
|
|
|
tanks: tanksWithConnectionStatus,
|
|
|
|
|
date: latestRecord.date,
|
|
|
|
|
time: latestRecord.time,
|
|
|
|
|
time: latestRecord.time
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -658,9 +662,6 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getByHardwareAndTankId = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId, tankhardwareId } = req.params;
|
|
|
|
@ -679,20 +680,17 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
return reply.code(404).send({ message: "No data found for given hardwareId and tankhardwareId" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 1: Check GSM Connection - if data is fresh within 1 minute
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const dataDate = new Date(latestData.date);
|
|
|
|
|
const diffInMs = now - dataDate;
|
|
|
|
|
const isGSMConnected = diffInMs <= 60000; // 60 seconds
|
|
|
|
|
const isGSMConnected = diffInMs <= 60000;
|
|
|
|
|
|
|
|
|
|
// Step 2: Find the matching tank
|
|
|
|
|
const matchedTank = latestData.tanks.find(tank => tank.tankhardwareId === tankhardwareId);
|
|
|
|
|
|
|
|
|
|
if (!matchedTank) {
|
|
|
|
|
return reply.code(404).send({ message: "Tank not found in latest record" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3: Determine LoRa connection status
|
|
|
|
|
const tankHeight = parseFloat(matchedTank.tankHeight || "0");
|
|
|
|
|
const isLoraConnected = isGSMConnected && tankHeight > 0;
|
|
|
|
|
|
|
|
|
@ -702,32 +700,33 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
const year = matchedTankDateObj.getFullYear();
|
|
|
|
|
const formattedDate = `${day}-${month}-${year}`;
|
|
|
|
|
|
|
|
|
|
// Add formatted date to matchedTank
|
|
|
|
|
matchedTank.date = formattedDate;
|
|
|
|
|
|
|
|
|
|
const updateFields = {
|
|
|
|
|
connected_status: isLoraConnected ? "connected" : "disconnected",
|
|
|
|
|
connected_status: isLoraConnected ? "connected" : "disconnected"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let connected_lora_date = null;
|
|
|
|
|
let connected_lora_time = null;
|
|
|
|
|
let lora_last_check_time = null;
|
|
|
|
|
|
|
|
|
|
if (isLoraConnected) {
|
|
|
|
|
connected_lora_date = formattedDate;
|
|
|
|
|
connected_lora_time = matchedTank.time || matchedTankDateObj.toTimeString().split(" ")[0];
|
|
|
|
|
|
|
|
|
|
updateFields.connected_lora_date = connected_lora_date;
|
|
|
|
|
updateFields.connected_lora_time = connected_lora_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 4: Update Insensors collection
|
|
|
|
|
// ✅ Format LoRa last check time in "YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
lora_last_check_time = moment.tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
updateFields.lora_last_check_time = lora_last_check_time;
|
|
|
|
|
|
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
|
{ connected_to: hardwareId, hardwareId: tankhardwareId },
|
|
|
|
|
{ $set: updateFields },
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Step 5: Prepare response
|
|
|
|
|
const displayMessage = isLoraConnected ? "LoRa connected" : "LoRa not connected";
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
@ -736,7 +735,8 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
data: matchedTank,
|
|
|
|
|
lora_connected_status: updateFields.connected_status,
|
|
|
|
|
connected_lora_date,
|
|
|
|
|
connected_lora_time
|
|
|
|
|
connected_lora_time,
|
|
|
|
|
lora_last_check_time
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
@ -749,6 +749,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getAllocatedSensorsByTank = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
let { customerId, tankName } = req.params;
|
|
|
|
|