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) => {
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;

@ -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: {

Loading…
Cancel
Save