feat: add metaFields to alerts
This commit is contained in:
@@ -11,6 +11,11 @@ export const alertsModel = mongoose.model(
|
||||
title: { type: String, required: true },
|
||||
referenceId: String,
|
||||
referenceCollection: String,
|
||||
metaFields: {
|
||||
client: { type: String, ref: "organization" },
|
||||
county: { type: String, ref: "organization" },
|
||||
permitType: String,
|
||||
},
|
||||
recipientType: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -31,6 +36,13 @@ const alertResponse = z.object({
|
||||
read: z.boolean(),
|
||||
referenceId: z.string().optional(),
|
||||
referenceCollection: z.string().optional(),
|
||||
metaFields: z
|
||||
.object({
|
||||
client: z.any().optional(),
|
||||
county: z.any().optional(),
|
||||
permitType: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
recipientType: z.enum(["user", "team"]),
|
||||
createdAt: z.date(),
|
||||
});
|
||||
|
||||
@@ -10,7 +10,12 @@ export async function createAlert(
|
||||
recipientType: "user" | "team",
|
||||
recipientId: string,
|
||||
referenceId?: string,
|
||||
referenceCollection?: string
|
||||
referenceCollection?: string,
|
||||
metaFields?: {
|
||||
client?: String;
|
||||
county?: String;
|
||||
permitType?: String;
|
||||
}
|
||||
) {
|
||||
const newAlert = await alertsModel.create({
|
||||
tenantId,
|
||||
@@ -20,6 +25,7 @@ export async function createAlert(
|
||||
recipientId,
|
||||
referenceId,
|
||||
referenceCollection,
|
||||
metaFields,
|
||||
});
|
||||
|
||||
dbEvents.emit(
|
||||
@@ -65,7 +71,9 @@ export async function getUserAlerts(
|
||||
})
|
||||
.sort({ createdAt: -1 })
|
||||
.limit(pageSize)
|
||||
.skip((page - 1) * pageSize);
|
||||
.skip((page - 1) * pageSize)
|
||||
.populate({ path: "metaFields.client", select: "pid name avatar" })
|
||||
.populate({ path: "metaFields.county", select: "pid name avatar" });
|
||||
|
||||
const modifiedAlerts = alerts.map((alert) => {
|
||||
return {
|
||||
|
||||
@@ -108,7 +108,11 @@ export async function updateNotification(
|
||||
"user",
|
||||
assignee,
|
||||
updateNotificationResult.pid,
|
||||
"permits"
|
||||
"permits",
|
||||
{
|
||||
client: updateNotificationResult.client.toString(),
|
||||
county: updateNotificationResult.county.id.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,11 @@ export async function updatePayment(
|
||||
"user",
|
||||
assignee,
|
||||
updatedPayment.pid,
|
||||
"tasks"
|
||||
"tasks",
|
||||
{
|
||||
client: updatedPayment.client.toString(),
|
||||
county: updatedPayment.county.id.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,6 @@ export async function updatePermit(
|
||||
{ ...input, lastUpdateDate: new Date() },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
|
||||
@@ -319,7 +318,11 @@ export async function updatePermit(
|
||||
"user",
|
||||
userId,
|
||||
updatePermitResult.pid,
|
||||
"permits"
|
||||
"permits",
|
||||
{
|
||||
client: updatePermitResult.client.toString(),
|
||||
county: updatePermitResult.county.id.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -358,7 +361,11 @@ export async function updatePermit(
|
||||
"user",
|
||||
assignee,
|
||||
updatePermitResult.pid,
|
||||
"permits"
|
||||
"permits",
|
||||
{
|
||||
client: updatePermitResult.client.toString(),
|
||||
county: updatePermitResult.county.id.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,11 @@ export async function updateProcessed(
|
||||
"user",
|
||||
assignee,
|
||||
updateProcessedResult.pid,
|
||||
"processed"
|
||||
"processed",
|
||||
{
|
||||
client: updateProcessedResult.client.toString(),
|
||||
county: updateProcessedResult.county.id.toString(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,8 +244,8 @@ export async function updateRts(
|
||||
new: true,
|
||||
})
|
||||
.populate({ path: "createdBy", select: "pid name avatar" })
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "county", select: "_id pid name avatar" })
|
||||
.populate({ path: "client", select: "_id pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||
|
||||
if (updateRts && input.permitType) {
|
||||
@@ -278,7 +278,14 @@ export async function updateRts(
|
||||
"user",
|
||||
assignee,
|
||||
updatedRts.pid,
|
||||
"rts"
|
||||
"rts",
|
||||
{
|
||||
//@ts-ignore
|
||||
client: updatedRts.client._id.toString(),
|
||||
//@ts-ignore
|
||||
county: updatedRts.county._id.toString(),
|
||||
permitType: updatedRts.permitType,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user