feat(sse): scope timeline events to affected audiences

This commit is contained in:
2026-03-30 00:40:24 +02:00
parent 819345acfa
commit fac8c1c3a5
8 changed files with 106 additions and 14 deletions
+12 -3
View File
@@ -1046,6 +1046,13 @@ export const allocationRouter = createTRPCRouter({
.input(z.object({ id: z.string(), data: UpdateAssignmentSchema }))
.mutation(async ({ ctx, input }) => {
requirePermission(ctx, PermissionKey.MANAGE_ALLOCATIONS);
const existing = await findUniqueOrThrow(
ctx.db.assignment.findUnique({
where: { id: input.id },
select: { resourceId: true },
}),
"Assignment",
);
const updated = await ctx.db.$transaction(async (tx) => {
return updateAssignment(
@@ -1059,6 +1066,7 @@ export const allocationRouter = createTRPCRouter({
id: updated.id,
projectId: updated.projectId,
resourceId: updated.resourceId,
resourceIds: [existing.resourceId, updated.resourceId],
});
dispatchAllocationWebhookInBackground(ctx.db, "allocation.updated", {
id: updated.id,
@@ -1192,6 +1200,7 @@ export const allocationRouter = createTRPCRouter({
id: updated.id,
projectId: updated.projectId,
resourceId: updated.resourceId,
resourceIds: [existing.entry.resourceId, updated.resourceId],
});
invalidateDashboardCacheInBackground();
checkBudgetThresholdsInBackground(ctx.db, updated.projectId);
@@ -1228,7 +1237,7 @@ export const allocationRouter = createTRPCRouter({
});
});
emitAllocationDeleted(existing.id, existing.projectId);
emitAllocationDeleted(existing.id, existing.projectId, existing.resourceId);
invalidateDashboardCacheInBackground();
checkBudgetThresholdsInBackground(ctx.db, existing.projectId);
@@ -1257,7 +1266,7 @@ export const allocationRouter = createTRPCRouter({
});
});
emitAllocationDeleted(existing.entry.id, existing.projectId);
emitAllocationDeleted(existing.entry.id, existing.projectId, existing.entry.resourceId);
invalidateDashboardCacheInBackground();
checkBudgetThresholdsInBackground(ctx.db, existing.projectId);
@@ -1292,7 +1301,7 @@ export const allocationRouter = createTRPCRouter({
});
for (const a of existing) {
emitAllocationDeleted(a.entry.id, a.projectId);
emitAllocationDeleted(a.entry.id, a.projectId, a.entry.resourceId);
}
invalidateDashboardCacheInBackground();
// Check budget thresholds for each affected project