call record status and time added

master^2
Bhaskar 3 months ago
parent 7cb64748c1
commit 6251bb0fbd

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

@ -295,6 +295,14 @@ const installationschema = new mongoose.Schema({
createdAt: { type: Date, default: Date.now } createdAt: { type: Date, default: Date.now }
}); });
const CallRecordSchema = new Schema({
call_status: { type: String },
call_time: { type: String },
customerId: String,
hardwareId: String,
createdAt: { type: Date, default: Date.now }
});
const supportschema = new mongoose.Schema({ const supportschema = new mongoose.Schema({
// name: { type: String }, // name: { type: String },
phone: { type: String, unique: true, trim: true }, phone: { type: String, unique: true, trim: true },
@ -321,7 +329,7 @@ const installationschema = new mongoose.Schema({
timeOfLogin: { type: String, default: null }, timeOfLogin: { type: String, default: null },
currentTime: { type: Date, default: Date.now }, currentTime: { type: Date, default: Date.now },
comments: [CommentSchema], comments: [CommentSchema],
callRecord: [CallRecordSchema],
lastTicketRaisedAt: {type : String}, lastTicketRaisedAt: {type : String},
issues: [IssueSchema], issues: [IssueSchema],

@ -582,29 +582,30 @@ module.exports = function (fastify, opts, next) {
fastify.put('/api/updateComments/:supportId', { fastify.put('/api/updateComments/:supportId', {
schema: { schema: {
description: "Update comments for a support record issue", description: "Update comments and call status for a support record issue",
tags: ["Support"], tags: ["Support"],
params: { params: {
type: "object", type: "object",
required: ["supportId"], required: ["supportId"],
properties: { properties: {
supportId: { type: "string", minLength: 1 }, supportId: { type: "string", minLength: 1 }
} }
}, },
body: { body: {
type: "object", type: "object",
required: ["comments"], required: ["customerId", "hardwareId", "comments", "call_status", "call_time"],
properties: { properties: {
customerId: { type: "string", minLength: 1 }, customerId: { type: "string", minLength: 1 },
hardwareId: { type: "string", minLength: 1 }, hardwareId: { type: "string", minLength: 1 },
comments: { type: "string", minLength: 1 } comments: { type: "string", minLength: 1 },
call_status: { type: "string", minLength: 1 },
call_time: { type: "string", minLength: 1 }
}
} }
},
}, },
handler: installationController.updateComments handler: installationController.updateComments
}); });
fastify.get("/api/getRemoveAllConnectedIsuues/:supportId/:hardwareId", { fastify.get("/api/getRemoveAllConnectedIsuues/:supportId/:hardwareId", {
schema: { schema: {
description: "Remove all connected list for Support", description: "Remove all connected list for Support",

Loading…
Cancel
Save