From 02501891a13acebe451cd4c25b0e76d742109b95 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 23 May 2025 13:06:47 +0530 Subject: [PATCH] get the categorized issues by added customer based details fetched --- src/controllers/installationController.js | 21 ++++++++++----------- src/routes/installationRoute.js | 15 ++++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index ecca47b3..13e14f53 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -5482,10 +5482,10 @@ exports.assignCategorizeIssue = async (request, reply) => { exports.getCategorizedIssue = async (request, reply) => { try { - const { support_teamMemberId } = request.params; + const { support_teamMemberId, customerId } = request.params; - if (!support_teamMemberId) { - return reply.code(400).send({ error: "support_teamMemberId is required" }); + if (!support_teamMemberId || !customerId) { + return reply.code(400).send({ error: "support_teamMemberId and customerId are required" }); } const supportRecords = await Support.find({ @@ -5507,10 +5507,11 @@ exports.getCategorizedIssue = async (request, reply) => { } const supportId = allIssues[0].supportId; - const hardwareIds = allIssues.map(issue => issue.hardwareId).filter(Boolean); - const masterHardwareIds = allIssues.map(issue => issue.masterHardwareId).filter(Boolean); + const hardwareIds = allIssues.map(i => i.hardwareId).filter(Boolean); + const masterHardwareIds = allIssues.map(i => i.masterHardwareId).filter(Boolean); const insensors = await Insensors.find({ + customerId, $or: [ { hardwareId: { $in: hardwareIds } }, { hardwareId: { $in: masterHardwareIds } } @@ -5519,12 +5520,10 @@ exports.getCategorizedIssue = async (request, reply) => { }).lean(); if (!insensors.length) { - return reply.code(404).send({ message: "No disconnected devices found for this team member." }); + return reply.code(404).send({ message: "No disconnected devices found for this customer and team member." }); } - const customerId = insensors[0]?.customerId || null; - const orders = customerId ? await Order.find({ customerId }).lean() : []; - + const orders = await Order.find({ customerId }).lean(); const orderMap = {}; orders.forEach(order => { order.master_connections?.forEach(conn => { @@ -5535,7 +5534,6 @@ exports.getCategorizedIssue = async (request, reply) => { }); }); - // Helper functions for formatting const formatDateIfValid = (value) => { const date = moment(value, "DD-MM-YYYY HH:mm:ss", true); return date.isValid() ? date.format("DD-MM-YYYY HH:mm:ss") : null; @@ -5549,7 +5547,6 @@ exports.getCategorizedIssue = async (request, reply) => { }; const disconnectedIssues = []; - const masters = insensors.filter(d => d.type === "master"); for (const master of masters) { @@ -5557,6 +5554,7 @@ exports.getCategorizedIssue = async (request, reply) => { if (!masterIssue) continue; const slaves = await Insensors.find({ + customerId, connected_to: master.hardwareId, connected_status: "disconnected", type: "slave" @@ -5629,6 +5627,7 @@ exports.getCategorizedIssue = async (request, reply) => { }; + exports.StatusTeamMember = async (request, reply) => { try { const { support_teamMemberId } = request.params; diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index ce4c6dd8..96b5f046 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -823,22 +823,23 @@ module.exports = function (fastify, opts, next) { }); - fastify.post("/api/my-categorized-issues/:support_teamMemberId", { + fastify.post("/api/my-categorized-issues/:support_teamMemberId/:customerId", { schema: { - description: "Get the categorized issues on particular team member", + description: "Get categorized issues by team member and customer", tags: ["Support"], - summary: "Get the categorized issues on particular team member", + summary: "Get categorized issues for a particular team member and customer", params: { type: "object", - required: ["support_teamMemberId"], + required: ["support_teamMemberId", "customerId"], properties: { support_teamMemberId: { type: "string" }, - }, - }, - + customerId: { type: "string" } + } + } }, handler: installationController.getCategorizedIssue }); + fastify.post("/api/updateStatusTeammember/:support_teamMemberId", { schema: {