|
|
|
@ -691,19 +691,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
|
const gsmStatus = isGSMConnected ? "connected" : "disconnected";
|
|
|
|
|
const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
await Insensors.updateMany(
|
|
|
|
|
{ connected_to: hardwareId },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
connected_gsm_date,
|
|
|
|
|
connected_gsm_time,
|
|
|
|
|
connected_status: gsmStatus,
|
|
|
|
|
support_gsm_last_check_time: gsmLastCheckTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await Insensors.updateOne(
|
|
|
|
|
await Insensors.findOneAndUpdate(
|
|
|
|
|
{ hardwareId },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
@ -728,7 +716,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
|
// 🔁 Raise ticket if applicable
|
|
|
|
|
const sensor = await Insensors.findOne({ hardwareId }).lean();
|
|
|
|
|
if (sensor?.customerId) {
|
|
|
|
|
await raiseATicketLikeLogic(sensor.customerId, hardwareId);
|
|
|
|
|
// await raiseATicketLikeLogic(sensor.customerId, hardwareId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
@ -746,9 +734,8 @@ exports.getByHardwareIdSupport = async (req, reply) => {
|
|
|
|
|
time: latestRecord.time
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error in getByHardwareIdSupport:", err);
|
|
|
|
|
console.error("Error in getByHardwareId:", err);
|
|
|
|
|
return reply.status(500).send({ error: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -4002,34 +3989,34 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// cron.schedule("* * * * *", async () => {
|
|
|
|
|
// try {
|
|
|
|
|
// console.log("🔁 Running auto-disconnect ticket check...");
|
|
|
|
|
// const allMasters = await Insensors.find({ type: "master" }).lean();
|
|
|
|
|
cron.schedule("* * * * *", async () => {
|
|
|
|
|
try {
|
|
|
|
|
console.log("🔁 Running auto-disconnect ticket check...");
|
|
|
|
|
const allMasters = await Insensors.find({ type: "master" }).lean();
|
|
|
|
|
|
|
|
|
|
// for (const master of allMasters) {
|
|
|
|
|
// const customerId = master.customerId;
|
|
|
|
|
// const hardwareId = master.hardwareId;
|
|
|
|
|
for (const master of allMasters) {
|
|
|
|
|
const customerId = master.customerId;
|
|
|
|
|
const hardwareId = master.hardwareId;
|
|
|
|
|
|
|
|
|
|
// const connectedSlaves = await Insensors.find({
|
|
|
|
|
// connected_to: hardwareId,
|
|
|
|
|
// type: "slave"
|
|
|
|
|
// }).lean();
|
|
|
|
|
const connectedSlaves = await Insensors.find({
|
|
|
|
|
connected_to: hardwareId,
|
|
|
|
|
type: "slave"
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
// const disconnectedSlaves = connectedSlaves.filter(
|
|
|
|
|
// s => s.connected_status === "disconnected"
|
|
|
|
|
// );
|
|
|
|
|
const disconnectedSlaves = connectedSlaves.filter(
|
|
|
|
|
s => s.connected_status === "disconnected"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// const masterIsDisconnected = master.connected_status === "disconnected";
|
|
|
|
|
const masterIsDisconnected = master.connected_status === "disconnected";
|
|
|
|
|
|
|
|
|
|
// if (masterIsDisconnected || disconnectedSlaves.length > 0) {
|
|
|
|
|
// await raiseATicketLikeLogic(customerId, hardwareId);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// console.error("Cron error:", err);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
if (masterIsDisconnected || disconnectedSlaves.length > 0) {
|
|
|
|
|
await raiseATicketLikeLogic(customerId, hardwareId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Cron error:", err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
exports.raiseATicketBuildingDetails = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|