feat: add more metaFields to alerts
This commit is contained in:
@@ -8,7 +8,7 @@ export async function createNote(
|
||||
input: CreateNoteInput,
|
||||
resourceId: string,
|
||||
resourceType: string,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const userIds = extractExpressions(input.content);
|
||||
|
||||
@@ -44,7 +44,7 @@ export async function createNote(
|
||||
orgs.push({ orgId: obj.client.toString(), taggedAt: new Date() });
|
||||
noteContent = noteContent.replaceAll(
|
||||
"{{client}}",
|
||||
`{{org-${obj.client.toString()}}}`,
|
||||
`{{org-${obj.client.toString()}}}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function createNote(
|
||||
orgs.push({ orgId: process.env.SUNCOAST_ID, taggedAt: new Date() });
|
||||
noteContent = noteContent.replaceAll(
|
||||
"{{agent}}",
|
||||
`{{org-${process.env.SUNCOAST_ID}}}`,
|
||||
`{{org-${process.env.SUNCOAST_ID}}}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -75,7 +75,7 @@ export async function createNote(
|
||||
if (!obj.taggedOrgs) obj.taggedOrgs = [];
|
||||
|
||||
const orgIndex = obj.taggedOrgs.findIndex(
|
||||
(item) => item.orgId == org.orgId,
|
||||
(item) => item.orgId == org.orgId
|
||||
);
|
||||
if (orgIndex != -1) obj.taggedOrgs[orgIndex].taggedAt = new Date();
|
||||
else obj.taggedOrgs.push(org);
|
||||
@@ -85,7 +85,7 @@ export async function createNote(
|
||||
if (!obj.taggedUsers) obj.taggedUsers = [];
|
||||
|
||||
const userIndex = obj.taggedUsers.findIndex(
|
||||
(item) => item.userId == user.userId,
|
||||
(item) => item.userId == user.userId
|
||||
);
|
||||
if (userIndex != -1) obj.taggedUsers[userIndex].taggedAt = new Date();
|
||||
else obj.taggedUsers.push(user);
|
||||
@@ -93,7 +93,7 @@ export async function createNote(
|
||||
|
||||
if (taggedUsers.length > 0) {
|
||||
const assignee = obj.assignedTo.find(
|
||||
(item) => item.toString() == taggedUsers[0].userId,
|
||||
(item) => item.toString() == taggedUsers[0].userId
|
||||
);
|
||||
|
||||
if (!assignee) obj.assignedTo.push(taggedUsers[0].userId);
|
||||
@@ -102,6 +102,26 @@ export async function createNote(
|
||||
obj.markModified("taggedUsers", "assignedTo", "taggedOrgs");
|
||||
await obj.save();
|
||||
|
||||
const metaFields: any = {};
|
||||
if (obj.client) metaFields.client = obj.client.toString();
|
||||
if (obj.county) {
|
||||
if (resourceType == "rts") metaFields.county = obj.county.toString();
|
||||
else metaFields.county = obj.county.id.toString();
|
||||
}
|
||||
if (obj.changes) metaFields.changes = obj.changes;
|
||||
if (obj.permitNumber) metaFields.permitNumber = obj.permitNumber;
|
||||
if (obj.cleanStatus) metaFields.standardStatus = obj.cleanStatus;
|
||||
if (obj.address) metaFields.address = obj.address;
|
||||
if (obj.lot) metaFields.lot = obj.lot;
|
||||
if (obj.block) metaFields.block = obj.block;
|
||||
if (obj.jobNumber) metaFields.jobNumber = obj.jobNumber;
|
||||
if (obj.permitType) metaFields.permitType = obj.permitType;
|
||||
if (obj.stage) metaFields.stage = obj.stage;
|
||||
if (obj.dueDate) metaFields.dueDate = obj.dueDate;
|
||||
if (obj.updatedAt) metaFields.updatedAt = obj.updatedAt;
|
||||
|
||||
metaFields.createdBy = user.userId;
|
||||
|
||||
if (taggedUsers.length > 0) {
|
||||
for (const taggedUser of taggedUsers) {
|
||||
if (taggedUser.userId == user.userId) continue;
|
||||
@@ -114,8 +134,8 @@ export async function createNote(
|
||||
resourceId,
|
||||
resourceType,
|
||||
{
|
||||
createdBy: user.userId,
|
||||
},
|
||||
...metaFields,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -130,8 +150,8 @@ export async function createNote(
|
||||
resourceId,
|
||||
resourceType,
|
||||
{
|
||||
createdBy: user.userId,
|
||||
},
|
||||
...metaFields,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +164,7 @@ export async function updateNote(
|
||||
input: CreateNoteInput,
|
||||
resourceId: string,
|
||||
noteId: string,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
) {
|
||||
return await noteModel
|
||||
.findOneAndUpdate(
|
||||
@@ -156,7 +176,7 @@ export async function updateNote(
|
||||
],
|
||||
},
|
||||
{ ...input },
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
}
|
||||
@@ -200,7 +220,7 @@ export async function listNotes(resourceId: string, tenantId: string) {
|
||||
export async function deleteNote(
|
||||
resourceId: string,
|
||||
noteId: string,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
) {
|
||||
return await noteModel.deleteOne({
|
||||
$and: [{ pid: noteId }, { tenantId: tenantId }, { resourceId: resourceId }],
|
||||
|
||||
Reference in New Issue
Block a user