ashok 6 months ago
commit 569dc63f8a

@ -3912,3 +3912,112 @@ exports.deleteTeamMemberSupport = async (req, reply)=> {
} }
} }
exports.moveIssueToCategory = async (req, reply) => {
try {
const { supportId, category } = req.body;
const { hardwareId, tankhardwareId } = req.body;
if (!supportId || !category || (!hardwareId && !tankhardwareId)) {
return reply.code(400).send({
message: "supportId, category, and hardwareId or tankhardwareId are required",
});
}
const support = await Support.findOne({ supportId });
if (!support) {
return reply.code(404).send({ message: "Support record not found" });
}
let issueMoved = false;
const nowTime = moment().tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm:ss");
// Ensure categorizedIssues array exists
if (!Array.isArray(support.categorizedIssues)) {
support.categorizedIssues = [];
}
// Master Issue Move
if (hardwareId && !tankhardwareId) {
const index = support.issues.findIndex(
(issue) => issue.hardwareId === hardwareId && issue.masterHardwareId === hardwareId
);
if (index !== -1) {
const issue = support.issues[index];
support.categorizedIssues.push({
...issue,
category,
movedAt: nowTime,
});
support.issues.splice(index, 1);
issueMoved = true;
}
}
// Slave Issue Move
if (tankhardwareId) {
for (let i = 0; i < support.issues.length; i++) {
const issue = support.issues[i];
const slaveIndex = issue.hardwareIds?.indexOf(tankhardwareId);
if (slaveIndex !== -1) {
const slaveName = issue.slaveNames?.[slaveIndex] || "Unknown";
// Add to categorized issues
support.categorizedIssues.push({
type: issue.type,
hardwareId: tankhardwareId,
masterHardwareId: issue.masterHardwareId,
slaveName,
category,
movedAt: nowTime,
});
// Remove from current issue
issue.hardwareIds.splice(slaveIndex, 1);
issue.slaveNames.splice(slaveIndex, 1);
// Remove issue completely if no more slaves
if (issue.hardwareIds.length === 0) {
support.issues.splice(i, 1);
}
issueMoved = true;
break;
}
}
}
if (issueMoved) {
await support.save();
return reply.send({ message: "Issue moved to category successfully" });
} else {
return reply.code(404).send({ message: "No matching issue found to move" });
}
} catch (err) {
console.error("Error moving issue:", err);
return reply.code(500).send({ error: "Internal Server Error" });
}
};
exports.particularCategory = async (req, reply) => {
const { supportId, category } = req.params;
const support = await Support.findOne({ supportId });
if (!support) {
return reply.code(404).send({ message: 'Support record not found' });
}
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}` });
}
return reply.send({ category, issues });
};

@ -239,6 +239,35 @@ const installationschema = new mongoose.Schema({
slaveHardwareId: String, slaveHardwareId: String,
slaveName: String, slaveName: String,
}], }],
categorizedIssues: [
{
type: {
type: String,
required: true
},
hardwareId: {
type: String,
required: true
},
masterHardwareId: {
type: String,
required: true
},
slaveName: {
type: String,
},
category: {
type: String,
enum: ["Power Outage", "Level1", "Pending", "Onsite Issues"],
required: true
},
movedAt: {
type: String, // or Date, depending on your preference
required: true
}
}
],
profile: { profile: {

@ -640,6 +640,51 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.post("/api/moveIssueToCategory", {
schema: {
description: "Move specific issue to a categorized bucket",
tags: ["Support"],
summary: "Move disconnected issue to category and remove from issues list",
body: {
type: "object",
required: ["supportId", "category"],
properties: {
supportId: { type: "string" },
category: {
type: "string",
enum: ["Power Outage", "Level1", "Pending", "Onsite Issues"]
},
hardwareId: { type: "string" }, // master
tankhardwareId: { type: "string" } // slave
}
}
},
handler: installationController.moveIssueToCategory
});
fastify.get('/api/support/categorizedIssues/:supportId/:category', {
schema: {
description: 'Get all issues in a particular category for a support record',
tags: ['Support'],
summary: 'Fetch issues by category',
params: {
type: 'object',
required: ['supportId', 'category'],
properties: {
supportId: { type: 'string' },
category: {
type: 'string',
enum: ['Power Outage', 'Level1', 'Pending', 'Onsite Issues'] // your allowed categories
}
}
},
},
handler: installationController.particularCategory
});
next(); next();

Loading…
Cancel
Save