|
|
|
@ -3884,8 +3884,7 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
|
|
|
|
|
const now = moment.tz("Asia/Kolkata");
|
|
|
|
|
|
|
|
|
|
// Get status from Insensors.connected_status directly
|
|
|
|
|
let masterConnectedStatus = masterSensor.connected_status || "disconnected";
|
|
|
|
|
const masterConnectedStatus = masterSensor.connected_status || "disconnected";
|
|
|
|
|
const lastDataTime = masterSensor.connected_gsm_date && masterSensor.connected_gsm_time
|
|
|
|
|
? `${masterSensor.connected_gsm_date} ${masterSensor.connected_gsm_time}`
|
|
|
|
|
: "No data";
|
|
|
|
@ -3902,22 +3901,32 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
slaveName: s.tankName || "Unknown Slave"
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (disconnectedSlaves.length === 0 && masterConnectedStatus === "connected") {
|
|
|
|
|
return; // ✅ No ticket needed
|
|
|
|
|
}
|
|
|
|
|
// No ticket needed if everything is connected
|
|
|
|
|
if (disconnectedSlaves.length === 0 && masterConnectedStatus === "connected") return;
|
|
|
|
|
|
|
|
|
|
const supportRecord = await Support.findOne({ supportId: "AWHYSU64" });
|
|
|
|
|
if (!supportRecord) return;
|
|
|
|
|
|
|
|
|
|
const existingIssues = supportRecord.issues || [];
|
|
|
|
|
const existingMasterIssue = existingIssues.find(
|
|
|
|
|
|
|
|
|
|
const unresolvedMasterIssue = existingIssues.find(
|
|
|
|
|
issue =>
|
|
|
|
|
issue.hardwareId === connected_to &&
|
|
|
|
|
issue.type === "GSM or LoRa Disconnected" &&
|
|
|
|
|
issue.resolved === false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Skip raising a ticket if unresolved issue already exists
|
|
|
|
|
if (unresolvedMasterIssue) return;
|
|
|
|
|
|
|
|
|
|
const resolvedMasterIssue = existingIssues.find(
|
|
|
|
|
issue =>
|
|
|
|
|
issue.hardwareId === connected_to &&
|
|
|
|
|
issue.type === "GSM or LoRa Disconnected" &&
|
|
|
|
|
issue.resolved !== true
|
|
|
|
|
issue.resolved === true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const alreadyReportedSlaves = new Set(existingMasterIssue?.hardwareIds || []);
|
|
|
|
|
const alreadyReportedSlaves = new Set(resolvedMasterIssue?.hardwareIds || []);
|
|
|
|
|
const newSlaveHardwareIds = [];
|
|
|
|
|
const newSlaveNames = [];
|
|
|
|
|
|
|
|
|
@ -3930,8 +3939,7 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
|
|
|
|
|
const formattedNow = now.format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
// Raise new issue
|
|
|
|
|
if (!existingMasterIssue && (masterConnectedStatus === "disconnected" || disconnectedSlaves.length > 0)) {
|
|
|
|
|
// Raise a new issue
|
|
|
|
|
const newIssue = {
|
|
|
|
|
type: "GSM or LoRa Disconnected",
|
|
|
|
|
masterHardwareId: connected_to,
|
|
|
|
@ -3943,37 +3951,12 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
lastTicketRaisedAt: formattedNow,
|
|
|
|
|
resolved: false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Support.findOneAndUpdate(
|
|
|
|
|
{ supportId: "AWHYSU64" },
|
|
|
|
|
{ $push: { issues: newIssue }, $set: { updatedAt: new Date() } }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update existing issue
|
|
|
|
|
if (existingMasterIssue && newSlaveHardwareIds.length > 0) {
|
|
|
|
|
await Support.findOneAndUpdate(
|
|
|
|
|
{ supportId: "AWHYSU64" },
|
|
|
|
|
{
|
|
|
|
|
$push: {
|
|
|
|
|
"issues.$[elem].hardwareIds": { $each: newSlaveHardwareIds },
|
|
|
|
|
"issues.$[elem].slaveNames": { $each: newSlaveNames }
|
|
|
|
|
},
|
|
|
|
|
$set: {
|
|
|
|
|
"issues.$[elem].lastTicketRaisedAt": formattedNow,
|
|
|
|
|
updatedAt: new Date()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
arrayFilters: [
|
|
|
|
|
{
|
|
|
|
|
"elem.hardwareId": connected_to,
|
|
|
|
|
"elem.type": "GSM or LoRa Disconnected",
|
|
|
|
|
"elem.resolved": false
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error in raiseATicketLikeLogic:", error);
|
|
|
|
|
}
|
|
|
|
@ -3981,6 +3964,7 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cron.schedule("* * * * *", async () => {
|
|
|
|
|
// console.log("Running auto ticket check...");
|
|
|
|
|
// const allMasters = await Insensors.find({ }).lean();
|
|
|
|
|