diff --git a/src/alert/alert.schema.ts b/src/alert/alert.schema.ts index e87bbb2..11696bf 100644 --- a/src/alert/alert.schema.ts +++ b/src/alert/alert.schema.ts @@ -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(), }); diff --git a/src/alert/alert.service.ts b/src/alert/alert.service.ts index 9226d49..722285c 100644 --- a/src/alert/alert.service.ts +++ b/src/alert/alert.service.ts @@ -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 { diff --git a/src/notification/notification.service.ts b/src/notification/notification.service.ts index 2cbc846..5cf7985 100644 --- a/src/notification/notification.service.ts +++ b/src/notification/notification.service.ts @@ -108,7 +108,11 @@ export async function updateNotification( "user", assignee, updateNotificationResult.pid, - "permits" + "permits", + { + client: updateNotificationResult.client.toString(), + county: updateNotificationResult.county.id.toString(), + } ); } diff --git a/src/payments/payments.service.ts b/src/payments/payments.service.ts index 16cc15b..7f8e6c2 100644 --- a/src/payments/payments.service.ts +++ b/src/payments/payments.service.ts @@ -175,7 +175,11 @@ export async function updatePayment( "user", assignee, updatedPayment.pid, - "tasks" + "tasks", + { + client: updatedPayment.client.toString(), + county: updatedPayment.county.id.toString(), + } ); } } diff --git a/src/permit/permit.service.ts b/src/permit/permit.service.ts index 9e9a445..35e180a 100644 --- a/src/permit/permit.service.ts +++ b/src/permit/permit.service.ts @@ -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(), + } ); } diff --git a/src/processed/processed.service.ts b/src/processed/processed.service.ts index ae397c9..2b73333 100644 --- a/src/processed/processed.service.ts +++ b/src/processed/processed.service.ts @@ -113,7 +113,11 @@ export async function updateProcessed( "user", assignee, updateProcessedResult.pid, - "processed" + "processed", + { + client: updateProcessedResult.client.toString(), + county: updateProcessedResult.county.id.toString(), + } ); } diff --git a/src/rts/rts.service.ts b/src/rts/rts.service.ts index 595f27e..fed1ec1 100644 --- a/src/rts/rts.service.ts +++ b/src/rts/rts.service.ts @@ -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, + } ); }