resolved issues fetch issues

master^2
Bhaskar 4 months ago
parent 8c67b06270
commit d88d2f1a04

@ -7115,19 +7115,23 @@ exports.particularCategory = async (req, reply) => {
return reply.code(400).send({ error: "supportId and category are required" }); return reply.code(400).send({ error: "supportId and category are required" });
} }
// Find support record
const support = await Support.findOne({ supportId }).lean(); const support = await Support.findOne({ supportId }).lean();
if (!support) { if (!support) {
return reply.code(404).send({ message: "Support record not found" }); return reply.code(404).send({ message: "Support record not found" });
} }
console.log("support",support)
// Filter issues by category // Choose the appropriate array based on category
const issues = (support.categorizedIssues || []).filter(issue => issue.category === category); let issues = [];
if (category === "Resolved") {
issues = (support.resolvedIssues || []).filter(issue => issue.category === "Resolved");
} else {
issues = (support.categorizedIssues || []).filter(issue => issue.category === category);
}
console.log("issues",issues)
if (issues.length === 0) { if (issues.length === 0) {
return reply.code(404).send({ message: `No issues found for category: ${category}` }); return reply.code(404).send({ message: `No issues found for category: ${category}` });
} }
// Get unique hardwareIds from the issues
const hardwareIds = [...new Set(issues.map(issue => issue.hardwareId).filter(Boolean))]; const hardwareIds = [...new Set(issues.map(issue => issue.hardwareId).filter(Boolean))];
if (hardwareIds.length === 0) { if (hardwareIds.length === 0) {
@ -7137,21 +7141,16 @@ exports.particularCategory = async (req, reply) => {
let customerId = queryCustomerId; let customerId = queryCustomerId;
if (!customerId) { if (!customerId) {
// Fetch sensors for these hardwareIds to find the customerId(s)
const sensors = await Insensors.find({ hardwareId: { $in: hardwareIds } }).lean(); const sensors = await Insensors.find({ hardwareId: { $in: hardwareIds } }).lean();
if (!sensors.length) { if (!sensors.length) {
return reply.code(404).send({ message: "No sensors found matching these hardware IDs" }); return reply.code(404).send({ message: "No sensors found matching these hardware IDs" });
} }
// Assuming all sensors belong to the same customer, get the first customerId
customerId = sensors[0].customerId; customerId = sensors[0].customerId;
if (!customerId) { if (!customerId) {
return reply.code(404).send({ message: "Customer ID not found for these sensors" }); return reply.code(404).send({ message: "Customer ID not found for these sensors" });
} }
} }
// Filter sensors only for this customer and hardwareIds (in case sensors contain mixed customers)
const allRelatedSensors = await Insensors.find({ const allRelatedSensors = await Insensors.find({
customerId, customerId,
hardwareId: { $in: hardwareIds } hardwareId: { $in: hardwareIds }
@ -7161,7 +7160,6 @@ exports.particularCategory = async (req, reply) => {
return reply.code(404).send({ message: "No sensors found for the provided customer and hardware IDs" }); return reply.code(404).send({ message: "No sensors found for the provided customer and hardware IDs" });
} }
// Map hardwareId to masterName and location from Orders
const orders = await Order.find({ customerId }).lean(); const orders = await Order.find({ customerId }).lean();
const orderMap = {}; const orderMap = {};
orders.forEach(order => { orders.forEach(order => {
@ -7175,15 +7173,12 @@ exports.particularCategory = async (req, reply) => {
const disconnectedIssues = []; const disconnectedIssues = [];
// For each master sensor
for (const master of allRelatedSensors.filter(i => i.type === "master")) { for (const master of allRelatedSensors.filter(i => i.type === "master")) {
// Get slaves connected to this master for the same customer
const slaves = await Insensors.find({ const slaves = await Insensors.find({
connected_to: master.hardwareId, connected_to: master.hardwareId,
customerId customerId
}).lean(); }).lean();
// Prepare slave details
const slaveDetails = await Promise.all(slaves.map(async (slave) => { const slaveDetails = await Promise.all(slaves.map(async (slave) => {
const slaveHardwareId = slave.tankhardwareId; const slaveHardwareId = slave.tankhardwareId;
@ -7258,6 +7253,7 @@ exports.particularCategory = async (req, reply) => {
// exports.assignCategorizeIssue = async (request, reply) => { // exports.assignCategorizeIssue = async (request, reply) => {
// const { supportId } = request.params; // const { supportId } = request.params;
// const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body; // const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;

Loading…
Cancel
Save