ashok 5 months ago
commit 735f3b634f

@ -5056,10 +5056,10 @@ exports.moveIssueToCategory = async (req, reply) => {
exports.particularCategory = async (req, reply) => {
try {
const { supportId, category } = req.params;
const { customerId, supportId, category } = req.params;
if (!supportId || !category) {
return reply.code(400).send({ error: "supportId and category are required" });
if (!customerId || !supportId || !category) {
return reply.code(400).send({ error: "customerId, supportId, and category are required" });
}
const support = await Support.findOne({ supportId }).lean();
@ -5067,13 +5067,20 @@ exports.particularCategory = async (req, reply) => {
return reply.code(404).send({ message: "Support record not found" });
}
const issues = (support.categorizedIssues || []).filter(issue => issue.category === category);
// Filter categorizedIssues by category and customerId
const 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 = issues.map(issue => issue.hardwareId).filter(Boolean);
// Only fetch sensors that belong to the customerId
const insensors = await Insensors.find({
customerId,
hardwareId: { $in: hardwareIds },
connected_status: "disconnected"
}).lean();
@ -5083,23 +5090,21 @@ exports.particularCategory = async (req, reply) => {
}
const orderMap = {};
const customerId = insensors[0]?.customerId;
if (customerId) {
const orders = await Order.find({ customerId }).lean();
orders.forEach(order => {
order.master_connections.forEach(conn => {
orderMap[conn.hardwareId] = {
masterName: conn.master_name || null,
location: conn.location || null
};
});
const orders = await Order.find({ customerId }).lean();
orders.forEach(order => {
order.master_connections.forEach(conn => {
orderMap[conn.hardwareId] = {
masterName: conn.master_name || null,
location: conn.location || null
};
});
}
});
const disconnectedIssues = [];
for (const master of insensors.filter(i => i.type === "master")) {
const slaves = await Insensors.find({
customerId,
connected_to: master.hardwareId,
connected_status: "disconnected"
}).lean();
@ -5118,7 +5123,7 @@ exports.particularCategory = async (req, reply) => {
typeOfWater: slave.typeOfWater || "",
support_lora_last_check_time: null,
category,
assignedTo: slaveIssue?.assignedTo || null // <-- Include assigned details here
assignedTo: slaveIssue?.assignedTo || null
};
});
@ -5135,13 +5140,14 @@ exports.particularCategory = async (req, reply) => {
connected_slave_count: slaveDetails.length,
connected_slaves: slaveDetails,
category,
assignedTo: masterIssue?.assignedTo || null // <-- Include assigned details here
assignedTo: masterIssue?.assignedTo || null
});
}
return reply.send({
status_code: 200,
supportId,
customerId,
totalMasters: disconnectedIssues.length,
disconnectedIssues
});
@ -5152,6 +5158,7 @@ exports.particularCategory = async (req, reply) => {
}
};
exports.assignCategorizeIssue = async (request, reply) => {
const { supportId } = request.params;
const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;

@ -745,7 +745,7 @@ module.exports = function (fastify, opts, next) {
handler: installationController.moveIssueToCategory
});
fastify.get('/api/support/categorizedIssues/:supportId/:category', {
fastify.get('/api/support/categorizedIssues/:supportId/:category/:customerId', {
schema: {
description: 'Get all issues in a particular category for a support record',
tags: ['Support'],
@ -755,6 +755,7 @@ module.exports = function (fastify, opts, next) {
required: ['supportId', 'category'],
properties: {
supportId: { type: 'string' },
customerId: { type: 'string' },
category: {
type: 'string',
enum: ['Power Outage', 'Level1', 'Pending', 'Onsite Issues'] // your allowed categories

Loading…
Cancel
Save