get the categorized issues by added customer based details fetched

master^2
Bhaskar 4 months ago
parent a2dd6ca34f
commit 02501891a1

@ -5482,10 +5482,10 @@ exports.assignCategorizeIssue = async (request, reply) => {
exports.getCategorizedIssue = async (request, reply) => { exports.getCategorizedIssue = async (request, reply) => {
try { try {
const { support_teamMemberId } = request.params; const { support_teamMemberId, customerId } = request.params;
if (!support_teamMemberId) { if (!support_teamMemberId || !customerId) {
return reply.code(400).send({ error: "support_teamMemberId is required" }); return reply.code(400).send({ error: "support_teamMemberId and customerId are required" });
} }
const supportRecords = await Support.find({ const supportRecords = await Support.find({
@ -5507,10 +5507,11 @@ exports.getCategorizedIssue = async (request, reply) => {
} }
const supportId = allIssues[0].supportId; const supportId = allIssues[0].supportId;
const hardwareIds = allIssues.map(issue => issue.hardwareId).filter(Boolean); const hardwareIds = allIssues.map(i => i.hardwareId).filter(Boolean);
const masterHardwareIds = allIssues.map(issue => issue.masterHardwareId).filter(Boolean); const masterHardwareIds = allIssues.map(i => i.masterHardwareId).filter(Boolean);
const insensors = await Insensors.find({ const insensors = await Insensors.find({
customerId,
$or: [ $or: [
{ hardwareId: { $in: hardwareIds } }, { hardwareId: { $in: hardwareIds } },
{ hardwareId: { $in: masterHardwareIds } } { hardwareId: { $in: masterHardwareIds } }
@ -5519,12 +5520,10 @@ exports.getCategorizedIssue = async (request, reply) => {
}).lean(); }).lean();
if (!insensors.length) { 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 = await Order.find({ customerId }).lean();
const orders = customerId ? await Order.find({ customerId }).lean() : [];
const orderMap = {}; const orderMap = {};
orders.forEach(order => { orders.forEach(order => {
order.master_connections?.forEach(conn => { order.master_connections?.forEach(conn => {
@ -5535,7 +5534,6 @@ exports.getCategorizedIssue = async (request, reply) => {
}); });
}); });
// Helper functions for formatting
const formatDateIfValid = (value) => { const formatDateIfValid = (value) => {
const date = moment(value, "DD-MM-YYYY HH:mm:ss", true); const date = moment(value, "DD-MM-YYYY HH:mm:ss", true);
return date.isValid() ? date.format("DD-MM-YYYY HH:mm:ss") : null; return date.isValid() ? date.format("DD-MM-YYYY HH:mm:ss") : null;
@ -5549,7 +5547,6 @@ exports.getCategorizedIssue = async (request, reply) => {
}; };
const disconnectedIssues = []; const disconnectedIssues = [];
const masters = insensors.filter(d => d.type === "master"); const masters = insensors.filter(d => d.type === "master");
for (const master of masters) { for (const master of masters) {
@ -5557,6 +5554,7 @@ exports.getCategorizedIssue = async (request, reply) => {
if (!masterIssue) continue; if (!masterIssue) continue;
const slaves = await Insensors.find({ const slaves = await Insensors.find({
customerId,
connected_to: master.hardwareId, connected_to: master.hardwareId,
connected_status: "disconnected", connected_status: "disconnected",
type: "slave" type: "slave"
@ -5629,6 +5627,7 @@ exports.getCategorizedIssue = async (request, reply) => {
}; };
exports.StatusTeamMember = async (request, reply) => { exports.StatusTeamMember = async (request, reply) => {
try { try {
const { support_teamMemberId } = request.params; const { support_teamMemberId } = request.params;

@ -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: { schema: {
description: "Get the categorized issues on particular team member", description: "Get categorized issues by team member and customer",
tags: ["Support"], tags: ["Support"],
summary: "Get the categorized issues on particular team member", summary: "Get categorized issues for a particular team member and customer",
params: { params: {
type: "object", type: "object",
required: ["support_teamMemberId"], required: ["support_teamMemberId", "customerId"],
properties: { properties: {
support_teamMemberId: { type: "string" }, support_teamMemberId: { type: "string" },
}, customerId: { type: "string" }
}, }
}
}, },
handler: installationController.getCategorizedIssue handler: installationController.getCategorizedIssue
}); });
fastify.post("/api/updateStatusTeammember/:support_teamMemberId", { fastify.post("/api/updateStatusTeammember/:support_teamMemberId", {
schema: { schema: {

Loading…
Cancel
Save