From 6251bb0fbd975d616af67ef0a29c05087bd6be8d Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 3 Jul 2025 11:44:48 +0530 Subject: [PATCH] call record status and time added --- src/controllers/installationController.js | 77 +++++++++++++++++------ src/models/store.js | 10 ++- src/routes/installationRoute.js | 49 ++++++++------- 3 files changed, 91 insertions(+), 45 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 22e81a3b..a159aab8 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -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; - - console.log("Incoming request body:", req.body); - console.log("typeof comments:", typeof comments); - console.log("value of comments:", comments); + const { comments, customerId, hardwareId, call_status, call_time } = req.body; - 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; diff --git a/src/models/store.js b/src/models/store.js index 372805cb..a2d184eb 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -295,6 +295,14 @@ const installationschema = new mongoose.Schema({ 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({ // name: { type: String }, phone: { type: String, unique: true, trim: true }, @@ -321,7 +329,7 @@ const installationschema = new mongoose.Schema({ timeOfLogin: { type: String, default: null }, currentTime: { type: Date, default: Date.now }, comments: [CommentSchema], - + callRecord: [CallRecordSchema], lastTicketRaisedAt: {type : String}, issues: [IssueSchema], diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index f6c48103..6bb92cb4 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -580,31 +580,32 @@ module.exports = function (fastify, opts, next) { handler: installationController.getResolvedIssuesBySupportId, }); - fastify.put('/api/updateComments/:supportId', { - schema: { - description: "Update comments for a support record issue", - tags: ["Support"], - params: { - type: "object", - required: ["supportId"], - properties: { - supportId: { type: "string", minLength: 1 }, - - } - }, - body: { - type: "object", - required: ["comments"], - properties: { - customerId: { type: "string", minLength: 1 }, - hardwareId: { type: "string", minLength: 1 }, - comments: { type: "string", minLength: 1 } - } - }, - + fastify.put('/api/updateComments/:supportId', { + schema: { + description: "Update comments and call status for a support record issue", + tags: ["Support"], + params: { + type: "object", + required: ["supportId"], + properties: { + supportId: { type: "string", minLength: 1 } + } }, - handler: installationController.updateComments - }); + body: { + type: "object", + required: ["customerId", "hardwareId", "comments", "call_status", "call_time"], + properties: { + customerId: { type: "string", minLength: 1 }, + hardwareId: { type: "string", minLength: 1 }, + comments: { type: "string", minLength: 1 }, + call_status: { type: "string", minLength: 1 }, + call_time: { type: "string", minLength: 1 } + } + } + }, + handler: installationController.updateComments + }); + fastify.get("/api/getRemoveAllConnectedIsuues/:supportId/:hardwareId", { schema: { description: "Remove all connected list for Support",