master^2
Bhaskar 4 months ago
parent 80758aff31
commit 9aa292e762

@ -7435,7 +7435,7 @@ exports.particularCategory = async (req, reply) => {
if (!support) {
return reply.code(404).send({ message: "Support record not found" });
}
console.log("support",support)
// Choose the appropriate array based on category
let issues = [];
if (category === "Resolved") {
@ -7443,7 +7443,7 @@ exports.particularCategory = async (req, reply) => {
} else {
issues = (support.categorizedIssues || []).filter(issue => issue.category === category);
}
console.log("issues",issues)
if (issues.length === 0) {
return reply.code(404).send({ message: `No issues found for category: ${category}` });
}
@ -7489,9 +7489,7 @@ exports.particularCategory = async (req, reply) => {
const disconnectedIssues = [];
const allMasters = allRelatedSensors.filter(i => i.type === "master");
for (const master of allMasters) {
for (const master of allRelatedSensors.filter(i => i.type === "master")) {
const slaves = await Insensors.find({
connected_to: master.hardwareId,
customerId
@ -7550,10 +7548,7 @@ exports.particularCategory = async (req, reply) => {
team_member_support_gsm_last_check_time: master.team_member_support_gsm_last_check_time || null,
connected_slave_count: slaveDetails.length,
connected_slaves: slaveDetails,
comments: masterComments,
isDisconnected:
master.connected_status === "disconnected" ||
slaveDetails.some(slave => slave.connected_status === "disconnected")
comments: masterComments
});
}
@ -7571,6 +7566,155 @@ exports.particularCategory = async (req, reply) => {
}
};
// exports.particularCategory = async (req, reply) => {
// try {
// const { supportId, category } = req.params;
// const { customerId: queryCustomerId } = req.query;
// if (!supportId || !category) {
// return reply.code(400).send({ error: "supportId and category are required" });
// }
// const support = await Support.findOne({ supportId }).lean();
// if (!support) {
// return reply.code(404).send({ message: "Support record not found" });
// }
// // Choose the appropriate array based on category
// let issues = [];
// if (category === "Resolved") {
// issues = (support.resolvedIssues || []).filter(issue => issue.category === "Resolved");
// } else {
// issues = (support.categorizedIssues || []).filter(issue => issue.category === category);
// }
// if (issues.length === 0) {
// return reply.code(404).send({ message: `No issues found for category: ${category}` });
// }
// const hardwareIds = [...new Set(issues.map(issue => issue.hardwareId).filter(Boolean))];
// if (hardwareIds.length === 0) {
// return reply.code(404).send({ message: "No hardware IDs found for these issues" });
// }
// let customerId = queryCustomerId;
// if (!customerId) {
// const sensors = await Insensors.find({ hardwareId: { $in: hardwareIds } }).lean();
// if (!sensors.length) {
// return reply.code(404).send({ message: "No sensors found matching these hardware IDs" });
// }
// customerId = sensors[0].customerId;
// if (!customerId) {
// return reply.code(404).send({ message: "Customer ID not found for these sensors" });
// }
// }
// const allRelatedSensors = await Insensors.find({
// customerId,
// hardwareId: { $in: hardwareIds }
// }).lean();
// if (!allRelatedSensors.length) {
// return reply.code(404).send({ message: "No sensors found for the provided customer and hardware IDs" });
// }
// const orders = await Order.find({ customerId }).lean();
// const orderMap = {};
// orders.forEach(order => {
// order.master_connections.forEach(conn => {
// orderMap[conn.hardwareId] = {
// masterName: conn.master_name || null,
// location: conn.location || null
// };
// });
// });
// const disconnectedIssues = [];
// const allMasters = allRelatedSensors.filter(i => i.type === "master");
// for (const master of allMasters) {
// const slaves = await Insensors.find({
// connected_to: master.hardwareId,
// customerId
// }).lean();
// const slaveDetails = await Promise.all(slaves.map(async (slave) => {
// const slaveHardwareId = slave.tankhardwareId;
// const tankInfo = await Tank.findOne({
// $or: [
// { hardwareId: slaveHardwareId },
// { tankhardwareId: slaveHardwareId }
// ]
// }).lean();
// const slaveComments = (support.comments || [])
// .filter(comment => comment.hardwareId === slave.hardwareId)
// .map(c => c.text);
// return {
// hardwareId: slave.tankhardwareId,
// tankName: slave.tankName || "",
// location: slave.tankLocation || "",
// connected_status: slave.connected_status,
// connected_lora_time: slave.connected_lora_time || "",
// connected_lora_date: slave.connected_lora_date || "",
// lora_last_check_time: slave.lora_last_check_time || null,
// lora_last_disconnect_time: slave.lora_last_disconnect_time || null,
// connected_to: slave.connected_to || "",
// masterName: orderMap[master.hardwareId]?.masterName || "",
// type: "slave",
// typeOfWater: tankInfo?.typeOfWater || "",
// support_lora_last_check_time: slave.support_lora_last_check_time || null,
// team_member_support_lora_last_check_time: slave.team_member_support_lora_last_check_time || null,
// comments: slaveComments
// };
// }));
// const masterComments = (support.comments || [])
// .filter(comment => comment.hardwareId === master.hardwareId)
// .map(c => c.text);
// disconnectedIssues.push({
// hardwareId: master.hardwareId,
// masterName: orderMap[master.hardwareId]?.masterName || "",
// location: orderMap[master.hardwareId]?.location || "",
// type: "master",
// connected_status: master.connected_status,
// gsm_last_check_time: master.gsm_last_check_time || null,
// gsm_last_disconnect_time: master.gsm_last_disconnect_time || null,
// connected_gsm_date: master.connected_gsm_date || "",
// connected_gsm_time: master.connected_gsm_time || "",
// connected_lora_date: master.connected_lora_date || "",
// connected_lora_time: master.connected_lora_time || "",
// support_gsm_last_check_time: master.support_gsm_last_check_time || null,
// team_member_support_gsm_last_check_time: master.team_member_support_gsm_last_check_time || null,
// connected_slave_count: slaveDetails.length,
// connected_slaves: slaveDetails,
// comments: masterComments,
// isDisconnected:
// master.connected_status === "disconnected" ||
// slaveDetails.some(slave => slave.connected_status === "disconnected")
// });
// }
// return reply.send({
// status_code: 200,
// supportId,
// customerId,
// totalMasters: disconnectedIssues.length,
// disconnectedIssues
// });
// } catch (err) {
// console.error("Error in particularCategory:", err);
// return reply.code(500).send({ error: "Internal server error" });
// }
// };

Loading…
Cancel
Save