|
|
|
@ -4557,42 +4557,85 @@ const generateTicketId = () => {
|
|
|
|
|
// console.log(`✅ New ticket raised for ${masterHardwareId}`);
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// const raiseATicketLikeLogic = async (supportRecord, masterHardwareId, slaveData = []) => {
|
|
|
|
|
// const now = new Date();
|
|
|
|
|
// const formattedNow = new Date(now.getTime() + 19800000) // +05:30 offset in ms
|
|
|
|
|
// .toISOString()
|
|
|
|
|
// .replace("T", " ")
|
|
|
|
|
// .substring(0, 19);
|
|
|
|
|
|
|
|
|
|
// // Check if already categorized
|
|
|
|
|
// const alreadyCategorized = supportRecord.categorizedIssues.some(
|
|
|
|
|
// (catIssue) => catIssue.hardwareId === masterHardwareId
|
|
|
|
|
// );
|
|
|
|
|
// if (alreadyCategorized) {
|
|
|
|
|
// console.log(`⛔ Ticket for ${masterHardwareId} already categorized. Skipping.`);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Check for existing unresolved, uncategorized ticket for same master
|
|
|
|
|
// const duplicateExists = supportRecord.issues.some((issue) => {
|
|
|
|
|
// return (
|
|
|
|
|
// issue.hardwareId === masterHardwareId &&
|
|
|
|
|
// issue.masterHardwareId === masterHardwareId &&
|
|
|
|
|
// issue.resolved === false &&
|
|
|
|
|
// issue.movedToCategory === false
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// if (duplicateExists) {
|
|
|
|
|
// console.log(`⛔ Duplicate unresolved issue already exists for ${masterHardwareId}. Skipping.`);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Prepare slave hardwareIds and names
|
|
|
|
|
// const slaveHardwareIds = slaveData.map((slave) => slave.tankhardwareId).sort();
|
|
|
|
|
// const slaveNames = slaveData.map((slave) => slave.sensorName || slave.tankName || "").sort();
|
|
|
|
|
|
|
|
|
|
// // Create new issue
|
|
|
|
|
// const newIssue = {
|
|
|
|
|
// type: "GSM or LoRa Disconnected",
|
|
|
|
|
// masterHardwareId,
|
|
|
|
|
// hardwareId: masterHardwareId,
|
|
|
|
|
// hardwareIds: slaveHardwareIds,
|
|
|
|
|
// slaveNames: slaveNames,
|
|
|
|
|
// resolved: false,
|
|
|
|
|
// movedToCategory: false,
|
|
|
|
|
// lastTicketRaisedAt: formattedNow,
|
|
|
|
|
// createdAt: formattedNow,
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// supportRecord.issues.push(newIssue);
|
|
|
|
|
// supportRecord.lastTicketRaisedAt = formattedNow;
|
|
|
|
|
|
|
|
|
|
// await supportRecord.save();
|
|
|
|
|
// console.log(`✅ New ticket raised for ${masterHardwareId}`);
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
const raiseATicketLikeLogic = async (supportRecord, masterHardwareId, slaveData = []) => {
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const formattedNow = new Date(now.getTime() + 19800000) // +05:30 offset in ms
|
|
|
|
|
const formattedNow = new Date(now.getTime() + 19800000) // +05:30 IST offset
|
|
|
|
|
.toISOString()
|
|
|
|
|
.replace("T", " ")
|
|
|
|
|
.substring(0, 19);
|
|
|
|
|
|
|
|
|
|
// Check if already categorized
|
|
|
|
|
const alreadyCategorized = supportRecord.categorizedIssues.some(
|
|
|
|
|
(catIssue) => catIssue.hardwareId === masterHardwareId
|
|
|
|
|
);
|
|
|
|
|
if (alreadyCategorized) {
|
|
|
|
|
console.log(`⛔ Ticket for ${masterHardwareId} already categorized. Skipping.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ✅ If issue already exists anywhere for this hardwareId, SKIP
|
|
|
|
|
const issueAlreadyExists = [
|
|
|
|
|
...supportRecord.issues,
|
|
|
|
|
...supportRecord.categorizedIssues,
|
|
|
|
|
...supportRecord.resolvedIssues
|
|
|
|
|
].some((issue) => issue.hardwareId === masterHardwareId);
|
|
|
|
|
|
|
|
|
|
// Check for existing unresolved, uncategorized ticket for same master
|
|
|
|
|
const duplicateExists = supportRecord.issues.some((issue) => {
|
|
|
|
|
return (
|
|
|
|
|
issue.hardwareId === masterHardwareId &&
|
|
|
|
|
issue.masterHardwareId === masterHardwareId &&
|
|
|
|
|
issue.resolved === false &&
|
|
|
|
|
issue.movedToCategory === false
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (duplicateExists) {
|
|
|
|
|
console.log(`⛔ Duplicate unresolved issue already exists for ${masterHardwareId}. Skipping.`);
|
|
|
|
|
if (issueAlreadyExists) {
|
|
|
|
|
console.log(`⛔ Issue already exists for ${masterHardwareId}. Not raising again.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepare slave hardwareIds and names
|
|
|
|
|
const slaveHardwareIds = slaveData.map((slave) => slave.tankhardwareId).sort();
|
|
|
|
|
const slaveNames = slaveData.map((slave) => slave.sensorName || slave.tankName || "").sort();
|
|
|
|
|
// ✅ Prepare slave hardwareIds and names
|
|
|
|
|
const slaveHardwareIds = slaveData.map((s) => s.tankhardwareId).sort();
|
|
|
|
|
const slaveNames = slaveData.map((s) => s.sensorName || s.tankName || "").sort();
|
|
|
|
|
|
|
|
|
|
// Create new issue
|
|
|
|
|
// ✅ Create new issue
|
|
|
|
|
const newIssue = {
|
|
|
|
|
type: "GSM or LoRa Disconnected",
|
|
|
|
|
masterHardwareId,
|
|
|
|
@ -4612,6 +4655,7 @@ const raiseATicketLikeLogic = async (supportRecord, masterHardwareId, slaveData
|
|
|
|
|
console.log(`✅ New ticket raised for ${masterHardwareId}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cron.schedule("*/1 * * * *", async () => {
|
|
|
|
|
try {
|
|
|
|
|
console.log("🔁 Running auto-disconnect ticket check...");
|
|
|
|
|