|
|
|
@ -6578,6 +6578,21 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
for (const master of Object.values(masterMap)) {
|
|
|
|
|
master.comments = comments;
|
|
|
|
|
|
|
|
|
|
const masterCallRecords = (supportRecord.callRecord || [])
|
|
|
|
|
.filter(record =>
|
|
|
|
|
record.customerId === customerId &&
|
|
|
|
|
record.hardwareId === master.hardwareId
|
|
|
|
|
)
|
|
|
|
|
.map(record => ({
|
|
|
|
|
call_status: record.call_status,
|
|
|
|
|
call_time: record.call_time,
|
|
|
|
|
createdAt: record.createdAt
|
|
|
|
|
? moment(record.createdAt).tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm")
|
|
|
|
|
: null
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
master.callRecord = masterCallRecords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
@ -10060,6 +10075,20 @@ if (!orders.length) {
|
|
|
|
|
: null
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const masterCallRecords = (support.callRecord || [])
|
|
|
|
|
.filter(call =>
|
|
|
|
|
call.hardwareId === master.hardwareId &&
|
|
|
|
|
call.customerId === customerId
|
|
|
|
|
)
|
|
|
|
|
.map(call => ({
|
|
|
|
|
call_status: call.call_status,
|
|
|
|
|
call_time: call.call_time,
|
|
|
|
|
createdAt: call.createdAt
|
|
|
|
|
? moment(call.createdAt).tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm")
|
|
|
|
|
: null
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const trimmedMasterId = (master.hardwareId || "").trim();
|
|
|
|
|
const orderDetails = orderMap[trimmedMasterId] || {};
|
|
|
|
|
console.log("📦 Resolved orderDetails for", trimmedMasterId, ":", orderDetails);
|
|
|
|
@ -10083,6 +10112,7 @@ if (!orders.length) {
|
|
|
|
|
support_gm_last_check_time: master.support_gsm_last_check_time || null,
|
|
|
|
|
connected_slaves: slaveDetails,
|
|
|
|
|
comments: masterComments,
|
|
|
|
|
callRecord: masterCallRecords,
|
|
|
|
|
outDoor_status: master.outDoor_status || "inprogress",
|
|
|
|
|
movedAt: category !== "Resolved" ? (issue?.movedAt || null) : null,
|
|
|
|
|
resolvedAt: category === "Resolved" ? (issue?.resolvedAt || null) : null,
|
|
|
|
@ -10624,14 +10654,10 @@ exports.StatusTeamMember = async (request, reply) => {
|
|
|
|
|
exports.updateComments = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supportId } = req.params;
|
|
|
|
|
const { comments, customerId, hardwareId } = req.body;
|
|
|
|
|
const { comments, customerId, hardwareId, call_status, call_time } = req.body;
|
|
|
|
|
|
|
|
|
|
console.log("Incoming request body:", req.body);
|
|
|
|
|
console.log("typeof comments:", typeof comments);
|
|
|
|
|
console.log("value of comments:", comments);
|
|
|
|
|
|
|
|
|
|
if (!supportId || !customerId || !hardwareId) {
|
|
|
|
|
return reply.code(400).send({ error: "supportId, customerId and hardwareId are required" });
|
|
|
|
|
if (!supportId || !customerId || !hardwareId || !call_status || !call_time) {
|
|
|
|
|
return reply.code(400).send({ error: "supportId, customerId, hardwareId, call_status, and call_time are required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trimmedComment = typeof comments === "string" ? comments.trim() : "";
|
|
|
|
@ -10646,9 +10672,7 @@ exports.updateComments = async (req, reply) => {
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
if (!sensor) {
|
|
|
|
|
return reply
|
|
|
|
|
.code(404)
|
|
|
|
|
.send({ error: "No sensor found with this hardwareId for this customerId" });
|
|
|
|
|
return reply.code(404).send({ error: "No sensor found with this hardwareId for this customerId" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 2: Load support record
|
|
|
|
@ -10667,12 +10691,10 @@ exports.updateComments = async (req, reply) => {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!issueExists) {
|
|
|
|
|
return reply
|
|
|
|
|
.code(404)
|
|
|
|
|
.send({ error: "HardwareId not found in issues or categorizedIssues for this support" });
|
|
|
|
|
return reply.code(404).send({ error: "HardwareId not found in issues or categorizedIssues for this support" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 4: Append comment object
|
|
|
|
|
// Step 4: Add comment
|
|
|
|
|
const commentObj = {
|
|
|
|
|
text: trimmedComment,
|
|
|
|
|
customerId,
|
|
|
|
@ -10680,29 +10702,44 @@ exports.updateComments = async (req, reply) => {
|
|
|
|
|
createdAt: new Date()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(supportRecord.comments)) {
|
|
|
|
|
supportRecord.comments = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
supportRecord.comments = supportRecord.comments || [];
|
|
|
|
|
supportRecord.comments.push(commentObj);
|
|
|
|
|
|
|
|
|
|
// Step 5: Add call record
|
|
|
|
|
const callRecordObj = {
|
|
|
|
|
call_status,
|
|
|
|
|
call_time,
|
|
|
|
|
customerId,
|
|
|
|
|
hardwareId,
|
|
|
|
|
createdAt: new Date()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
supportRecord.callRecord = supportRecord.callRecord || [];
|
|
|
|
|
supportRecord.callRecord.push(callRecordObj);
|
|
|
|
|
|
|
|
|
|
// Save support record
|
|
|
|
|
await supportRecord.save();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
message: "Comment added successfully",
|
|
|
|
|
message: "Comment and call record added successfully",
|
|
|
|
|
comment: {
|
|
|
|
|
...commentObj,
|
|
|
|
|
createdAt: moment(commentObj.createdAt).format("DD-MM-YYYY HH:mm")
|
|
|
|
|
},
|
|
|
|
|
callRecord: {
|
|
|
|
|
...callRecordObj,
|
|
|
|
|
createdAt: moment(callRecordObj.createdAt).format("DD-MM-YYYY HH:mm")
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error updating comments:", error);
|
|
|
|
|
console.error("Error updating comments/callRecord:", error);
|
|
|
|
|
return reply.code(500).send({ error: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.resolvedIssuesForSupport = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supportId } = req.params;
|
|
|
|
|