|
|
|
@ -2289,6 +2289,8 @@ exports.getIotDataByCustomerAndHardwareId = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//const moment = require("moment-timezone");
|
|
|
|
|
|
|
|
|
|
exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId, connected_to } = req.params;
|
|
|
|
@ -2303,7 +2305,7 @@ exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
return reply.code(404).send({ message: "No sensors found for this customer." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const masterSensor = sensors.find(s => (s.hardwareId?.trim() === connected_to.trim()));
|
|
|
|
|
const masterSensor = sensors.find(s => s.hardwareId?.trim() === connected_to.trim() && s.type === "master");
|
|
|
|
|
|
|
|
|
|
if (!masterSensor) {
|
|
|
|
|
return reply.code(404).send({ message: "Master hardwareId not found." });
|
|
|
|
@ -2315,31 +2317,20 @@ exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
return reply.code(404).send({ message: "No IoT data found for this hardwareId." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debugging log to check the fetched date and current time
|
|
|
|
|
console.log("Latest Master Record Date:", latestMasterRecord.date);
|
|
|
|
|
|
|
|
|
|
const indiaTime = moment.tz(latestMasterRecord.date, "Asia/Kolkata");
|
|
|
|
|
const now = moment.tz("Asia/Kolkata");
|
|
|
|
|
|
|
|
|
|
// Log the current time and difference
|
|
|
|
|
console.log("Current Time:", now.format("DD-MM-YYYY HH:mm:ss"));
|
|
|
|
|
|
|
|
|
|
const diffInMinutesMaster = now.diff(indiaTime, "minutes");
|
|
|
|
|
|
|
|
|
|
// Log the time difference
|
|
|
|
|
console.log("Time difference in minutes (Master):", diffInMinutesMaster);
|
|
|
|
|
|
|
|
|
|
// Update masterDisconnected to store details
|
|
|
|
|
const masterDisconnected = diffInMinutesMaster > 1 ? [{
|
|
|
|
|
hardwareId: connected_to,
|
|
|
|
|
masterName: masterSensor.tankName,
|
|
|
|
|
disconnectedAt: moment().tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss"),
|
|
|
|
|
masterName: masterSensor.tankName || masterSensor.tankName || "Unknown Master",
|
|
|
|
|
// disconnectedAt: now.format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
}] : [];
|
|
|
|
|
|
|
|
|
|
// Log the disconnected status
|
|
|
|
|
console.log("Master Disconnected:", masterDisconnected);
|
|
|
|
|
|
|
|
|
|
const connectedSlaves = sensors.filter(sensor => sensor.connected_to?.trim() === connected_to.trim());
|
|
|
|
|
const connectedSlaves = sensors.filter(sensor =>
|
|
|
|
|
sensor.connected_to?.trim() === connected_to.trim() &&
|
|
|
|
|
sensor.type === "slave"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const disconnectedSlaves = [];
|
|
|
|
|
|
|
|
|
@ -2353,8 +2344,9 @@ exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
if (loraDiffInMinutes > 1) {
|
|
|
|
|
disconnectedSlaves.push({
|
|
|
|
|
hardwareId: connected_to,
|
|
|
|
|
slaveHardwareId: slaveId,
|
|
|
|
|
slaveName: slave.tankName
|
|
|
|
|
slaveName: slave.tankName || "Unknown Slave"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2363,21 +2355,46 @@ exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
const issuesToAdd = [];
|
|
|
|
|
|
|
|
|
|
if (masterDisconnected.length > 0) {
|
|
|
|
|
const existingGsmIssue = await Support.findOne({
|
|
|
|
|
"issues.hardwareId": connected_to,
|
|
|
|
|
"issues.type": "GSM Disconnected"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!existingGsmIssue) {
|
|
|
|
|
issuesToAdd.push({
|
|
|
|
|
type: "GSM Disconnected",
|
|
|
|
|
hardwareId: connected_to,
|
|
|
|
|
message: `Master GSM disconnected - ${connected_to}`,
|
|
|
|
|
disconnectedAt: moment().tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
//disconnectedAt: now.format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disconnectedSlaves.length > 0) {
|
|
|
|
|
// Check for already existing slave issues
|
|
|
|
|
const newHardwareIds = [];
|
|
|
|
|
const newSlaveNames = [];
|
|
|
|
|
|
|
|
|
|
for (const slave of disconnectedSlaves) {
|
|
|
|
|
const existingSlaveIssue = await Support.findOne({
|
|
|
|
|
"issues.hardwareIds": slave.slaveHardwareId,
|
|
|
|
|
"issues.masterHardwareId": connected_to,
|
|
|
|
|
"issues.type": "LoRa Disconnected"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!existingSlaveIssue) {
|
|
|
|
|
newHardwareIds.push(slave.slaveHardwareId);
|
|
|
|
|
newSlaveNames.push(slave.slaveName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newHardwareIds.length > 0) {
|
|
|
|
|
issuesToAdd.push({
|
|
|
|
|
type: "LoRa Disconnected",
|
|
|
|
|
hardwareIds: disconnectedSlaves.map(d => d.slaveHardwareId),
|
|
|
|
|
slaveNames: disconnectedSlaves.map(d => d.slaveName),
|
|
|
|
|
message: `Slaves LoRa disconnected`,
|
|
|
|
|
disconnectedAt: moment().tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
masterHardwareId: connected_to,
|
|
|
|
|
hardwareIds: newHardwareIds,
|
|
|
|
|
slaveNames: newSlaveNames,
|
|
|
|
|
message: `Slaves LoRa disconnected under master ${connected_to}`,
|
|
|
|
|
// disconnectedAt: now.format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2414,6 +2431,8 @@ exports.raiseATicket = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.raiseATicketBuildingDetails = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId, connected_to, installationId } = req.params;
|
|
|
|
|