feat: replace client, agent in the content of the note with their respsective ids

This commit is contained in:
2026-01-27 13:47:02 +05:30
parent 286c6c5565
commit cf9cfc0756
2 changed files with 21 additions and 3 deletions

View File

@@ -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) => {

View File

@@ -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,