From cf9cfc0756e9586bc7dcfccc8d1ce748c532d96d Mon Sep 17 00:00:00 2001 From: Akhil Meka Date: Tue, 27 Jan 2026 13:47:02 +0530 Subject: [PATCH] feat: replace client, agent in the content of the note with their respsective ids --- src/note/note.service.ts | 22 ++++++++++++++++++++-- src/notification/notification.schema.ts | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/note/note.service.ts b/src/note/note.service.ts index ab298c4..30635b4 100644 --- a/src/note/note.service.ts +++ b/src/note/note.service.ts @@ -36,14 +36,32 @@ export async function createNote( const model = modelMap[resourceType]; const obj = await model.findOne({ pid: resourceId }); + let noteContent = newNote.content; + const orgs = []; userIds.forEach((item) => { - if (item == "client" && obj.client) + if (item == "client" && obj.client) { orgs.push({ orgId: obj.client.toString(), taggedAt: new Date() }); - if (item == "agent") + noteContent = noteContent.replaceAll( + "{{client}}", + `{{${obj.client.toString()}}`, + ); + } + + if (item == "agent") { orgs.push({ orgId: process.env.SUNCOAST_ID, taggedAt: new Date() }); + noteContent = noteContent.replaceAll( + "{{agent}}", + `{{${process.env.SUNCOAST_ID}}`, + ); + } }); + if (noteContent != newNote.content) { + newNote.content = noteContent; + await newNote.save(); + } + const taggedUsers = userIds .filter((item) => !["client", "agent"].includes(item)) .map((item) => { diff --git a/src/notification/notification.schema.ts b/src/notification/notification.schema.ts index ea800d8..0f5524f 100644 --- a/src/notification/notification.schema.ts +++ b/src/notification/notification.schema.ts @@ -22,7 +22,7 @@ const notificationSchema = new mongoose.Schema({ name: String, avatar: String, }, - client: mongoose.Types.ObjectId, + client: { type: mongoose.Types.ObjectId, ref: "organization" }, clientData: Object, createdAt: Date, updatedAt: Date,