feat(sse): scope timeline events to affected audiences
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1315,6 +1315,7 @@ export const timelineRouter = createTRPCRouter({
|
||||
newStartDate: newStartDate.toISOString(),
|
||||
newEndDate: newEndDate.toISOString(),
|
||||
costDeltaCents: validation.costImpact.deltaCents,
|
||||
resourceIds: assignments.map((assignment) => assignment.resourceId),
|
||||
});
|
||||
|
||||
return { project: updatedProject, validation };
|
||||
|
||||
Reference in New Issue
Block a user