|
|
|
@ -7115,19 +7115,23 @@ exports.particularCategory = async (req, reply) => {
|
|
|
|
|
return reply.code(400).send({ error: "supportId and category are required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find support record
|
|
|
|
|
const support = await Support.findOne({ supportId }).lean();
|
|
|
|
|
if (!support) {
|
|
|
|
|
return reply.code(404).send({ message: "Support record not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter issues by category
|
|
|
|
|
const issues = (support.categorizedIssues || []).filter(issue => issue.category === category);
|
|
|
|
|
console.log("support",support)
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
console.log("issues",issues)
|
|
|
|
|
if (issues.length === 0) {
|
|
|
|
|
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))];
|
|
|
|
|
|
|
|
|
|
if (hardwareIds.length === 0) {
|
|
|
|
@ -7137,21 +7141,16 @@ exports.particularCategory = async (req, reply) => {
|
|
|
|
|
let customerId = queryCustomerId;
|
|
|
|
|
|
|
|
|
|
if (!customerId) {
|
|
|
|
|
// Fetch sensors for these hardwareIds to find the customerId(s)
|
|
|
|
|
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" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assuming all sensors belong to the same customer, get the first customerId
|
|
|
|
|
customerId = sensors[0].customerId;
|
|
|
|
|
if (!customerId) {
|
|
|
|
|
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({
|
|
|
|
|
customerId,
|
|
|
|
|
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" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Map hardwareId to masterName and location from Orders
|
|
|
|
|
const orders = await Order.find({ customerId }).lean();
|
|
|
|
|
const orderMap = {};
|
|
|
|
|
orders.forEach(order => {
|
|
|
|
@ -7175,15 +7173,12 @@ exports.particularCategory = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
const disconnectedIssues = [];
|
|
|
|
|
|
|
|
|
|
// For each master sensor
|
|
|
|
|
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({
|
|
|
|
|
connected_to: master.hardwareId,
|
|
|
|
|
customerId
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
// Prepare slave details
|
|
|
|
|
const slaveDetails = await Promise.all(slaves.map(async (slave) => {
|
|
|
|
|
const slaveHardwareId = slave.tankhardwareId;
|
|
|
|
|
|
|
|
|
@ -7258,6 +7253,7 @@ exports.particularCategory = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.assignCategorizeIssue = async (request, reply) => {
|
|
|
|
|
// const { supportId } = request.params;
|
|
|
|
|
// const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;
|
|
|
|
@ -7756,7 +7752,7 @@ exports.resolvedIssuesForSupport = async (req, reply) => {
|
|
|
|
|
support.categorizedIssues[categorizedIndex].movedToCategory = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await support.save();
|
|
|
|
|
return reply.send({
|
|
|
|
|