feat: replace client, agent in the content of the note with their respsective ids
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user