master^2
Varun 1 week ago
parent 2758abe8c8
commit 048bd5c188

@ -16,7 +16,7 @@ exports.options = {
// we have to run on this on swagger
// host: "localhost:3000", //Devlopemnt host on lcoal
//host: "35.207.205.18:3000", //Production for swagger
host: "armintaaqua.com:3000", //Production for swagger
schemes: ["http"],
consumes: ["application/json"],
produces: ["application/json"],

@ -6080,171 +6080,70 @@ exports.updateHardwareList = async (req, reply) => {
// exports.assignCategorizeIssue = async (request, reply) => {
// const { supportId } = request.params;
// const { support_teamMemberId, category, masterHardwareId } = request.body;
// if (!support_teamMemberId || !category || !masterHardwareId) {
// return reply.code(400).send({
// error: 'support_teamMemberId, category, and masterHardwareId are required'
// });
// }
// const support = await Support.findOne({ supportId });
// if (!support) {
// return reply.code(404).send({ error: 'Support record not found' });
// }
// const teamMembers = support.team_member?.team_member || [];
// const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
// if (!teamMember) {
// return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
// }
// const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
// const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
// let assignedCount = 0;
// support.categorizedIssues.forEach(issue => {
// if (
// issue.masterHardwareId === masterHardwareId &&
// issue.category === category
// ) {
// issue.assignedTo = {
// name: teamMember.name,
// support_teamMemberId: teamMember.support_teamMemberId,
// phone: teamMember.phone,
// email: teamMember.email,
// assignedAt: assignedAt,
// assignmentCode: assignmentCode // ← Add this field
// };
// assignedCount++;
// }
// });
// if (assignedCount === 0) {
// return reply.code(404).send({ message: 'No matching issues found for assignment' });
// }
// await support.save();
// return reply.send({
// message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
// assignmentCode: assignmentCode, // ← Return the code in response
// assignedTo: {
// support_teamMemberId: teamMember.support_teamMemberId,
// name: teamMember.name,
// phone: teamMember.phone,
// email: teamMember.email,
// assignedAt: assignedAt,
// }
// });
// };
exports.assignCategorizeIssue = async (request, reply) => {
try {
const { supportId } = request.params;
const { support_teamMemberId, quationId } = request.body;
const { supportId } = request.params;
const { support_teamMemberId, category, masterHardwareId } = request.body;
// Step 1: Validate input
if (!supportId || !support_teamMemberId || !quationId) {
return reply.code(400).send({
error: 'supportId (path), support_teamMemberId, and quationId (body) are required'
});
}
if (!support_teamMemberId || !category || !masterHardwareId) {
return reply.code(400).send({
error: 'support_teamMemberId, category, and masterHardwareId are required'
});
}
// Step 2: Find support record
const support = await Support.findOne({ supportId });
if (!support) {
return reply.code(404).send({ error: 'Support record not found' });
}
const support = await Support.findOne({ supportId });
if (!support) {
return reply.code(404).send({ error: 'Support record not found' });
}
// Step 3: Check team member exists
const teamMembers = support.team_member?.team_member || [];
const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
const teamMembers = support.team_member?.team_member || [];
const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
if (!teamMember) {
return reply.code(404).send({ error: `Team member ID ${support_teamMemberId} not found` });
}
if (!teamMember) {
return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
}
// Step 4: Assign all categorized issues
const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
let assignedCount = 0;
const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
let assignedCount = 0;
support.issues.forEach(issue => {
support.categorizedIssues.forEach(issue => {
if (
issue.masterHardwareId === masterHardwareId &&
issue.category === category
) {
issue.assignedTo = {
name: teamMember.name,
support_teamMemberId: teamMember.support_teamMemberId,
phone: teamMember.phone,
email: teamMember.email,
assignedAt: assignedAt,
assignmentCode: assignmentCode,
quationId: quationId
assignmentCode: assignmentCode // ← Add this field
};
assignedCount++;
});
if (assignedCount === 0) {
return reply.code(404).send({ message: 'No categorized issues found to assign' });
}
});
// Step 5: Save support document
await support.save();
// Step 6: Update or create the Order document with assigned support team member
let order = await Order.findOne({ quatationId: quationId });
if (assignedCount === 0) {
return reply.code(404).send({ message: 'No matching issues found for assignment' });
}
if (!order) {
order = new Order({
quatationId: quationId,
assignedTeamMembers: [],
quatation_status: "Assigned",
});
}
await support.save();
// Save the assigned support team member info
order.assignedSupportTeamMember = {
return reply.send({
message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
assignmentCode: assignmentCode, // ← Return the code in response
assignedTo: {
support_teamMemberId: teamMember.support_teamMemberId,
name: teamMember.name,
phone: teamMember.phone,
email: teamMember.email,
assignedAt: assignedAt,
assignmentCode: assignmentCode,
quationId: quationId,
};
}
});
};
await order.save();
// Step 7: Return response
return reply.send({
simplydata: {
error: false,
message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
assignmentCode: assignmentCode,
assignedTo: {
support_teamMemberId: teamMember.support_teamMemberId,
name: teamMember.name,
phone: teamMember.phone,
email: teamMember.email,
assignedAt: assignedAt,
quationId: quationId
}
}
});
} catch (error) {
console.error("Error assigning categorized issues:", error);
return reply.status(500).send({
simplydata: {
error: true,
message: "Internal Server Error"
}
});
}
};
exports.getCategorizedIssue = async (request, reply) => {

File diff suppressed because it is too large Load Diff

@ -914,15 +914,6 @@ const orderSchema = new mongoose.Schema({
datetime: { type: String, default: null },
updated_at: { type: String, default: null },
assignedTeamMembers: [{ type: String }],
assignedSupportTeamMember: {
support_teamMemberId: { type: String },
name: { type: String },
phone: { type: String },
email: { type: String },
assignedAt: { type: String },
assignmentCode: { type: String },
quationId: { type: String },
},
tankhardwareId: [{ type: String,default: null }],
master_connections: [
{

@ -159,7 +159,6 @@ const supplierSchema = new mongoose.Schema(
});
const requestedSupplierSchema = new mongoose.Schema({
supplierId: String,

@ -67,7 +67,6 @@ const tanksSchema = new mongoose.Schema({
slave_status:{ type: String, default: "working" },
slave_disconnected_time :{ type: String, default: null },
connections: {
source: { type: String },
inputConnections: [
@ -242,7 +241,6 @@ const TankConsumptionSchema = mongoose.model("TankConsumptionSchema", tankconsum
const TankConsumptionOriginalSchema = mongoose.model("TankConsumptionOriginalSchema", tankconsumptionoriginalSchema);
module.exports = {
Tank, MotorData,IotData,TankWaterLevel,TankConsumptionSchema,TankConsumptionOriginalSchema,CustomerAutoPercentages
}

@ -1325,8 +1325,8 @@ fastify.post(
support_teamMemberId: { type: "string" },
// startDate: { type: "string" },
// endDate: { type: "string" },
//category: { type: "string" },
quationId: { type: "string" },
category: { type: "string" },
masterHardwareId: { type: "string" },
},
},
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Loading…
Cancel
Save