feat: Sprint 1 — staffing assign, dashboard cache, bulk ops, notifications

Staffing "Assign" Button:
- Inline assignment form on each suggestion card in StaffingPanel
- Pre-fills project, dates, hours from search criteria
- 1-click confirm creates allocation with PROPOSED status
- Success/error toasts, removes assigned suggestions from list

Dashboard Redis Caching:
- New cache utility (packages/api/src/lib/cache.ts) with get/set/invalidate
- All 5 dashboard queries wrapped with 60s TTL cache-aside pattern
- Auto-invalidation on allocation + project mutations (fire-and-forget)
- Graceful fallthrough to DB if Redis unavailable

Bulk Operations:
- CSV export for selected resources and projects (apps/web/src/lib/csv-export.ts)
- Project batch delete mutation with cascade (assignments, demands, rules)
- Export/Delete buttons added to BatchActionBar on both list pages

Budget Overrun Notifications:
- checkBudgetThresholds() alerts at 80% (HIGH) and 100% (URGENT)
- Called after every allocation mutation, duplicate-safe
- Targets ADMIN + MANAGER users with SSE delivery

Estimate Approval Reminders:
- checkPendingEstimateReminders() finds SUBMITTED versions > 3 days old
- Cron endpoint: GET /api/cron/estimate-reminders (optional CRON_SECRET auth)
- Creates in-app REMINDER notifications, duplicate-safe

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-19 20:43:36 +01:00
parent 0d78fe1770
commit 4118995319
14 changed files with 1042 additions and 71 deletions
+49
View File
@@ -29,7 +29,9 @@ import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { findUniqueOrThrow } from "../db/helpers.js";
import { anonymizeResource, getAnonymizationDirectory } from "../lib/anonymization.js";
import { checkBudgetThresholds } from "../lib/budget-alerts.js";
import { emitAllocationCreated, emitAllocationDeleted, emitAllocationUpdated, emitNotificationCreated } from "../sse/event-bus.js";
import { invalidateDashboardCache } from "../lib/cache.js";
import { createTRPCRouter, managerProcedure, protectedProcedure, requirePermission } from "../trpc.js";
import { PROJECT_BRIEF_SELECT, RESOURCE_BRIEF_SELECT, ROLE_BRIEF_SELECT } from "../db/selects.js";
@@ -242,6 +244,9 @@ export const allocationRouter = createTRPCRouter({
projectId: allocation.projectId,
resourceId: allocation.resourceId,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, allocation.projectId);
return allocation;
}),
@@ -445,6 +450,7 @@ export const allocationRouter = createTRPCRouter({
projectId: demandRequirement.projectId,
resourceId: null,
});
void invalidateDashboardCache();
// Create staffing tasks for managers
const [project, roleEntity, managers] = await Promise.all([
@@ -487,6 +493,8 @@ export const allocationRouter = createTRPCRouter({
emitNotificationCreated(manager.id, task.id);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, demandRequirement.projectId);
return demandRequirement;
}),
@@ -508,6 +516,9 @@ export const allocationRouter = createTRPCRouter({
projectId: updated.projectId,
resourceId: null,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, updated.projectId);
return updated;
}),
@@ -529,6 +540,9 @@ export const allocationRouter = createTRPCRouter({
projectId: assignment.projectId,
resourceId: assignment.resourceId,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, assignment.projectId);
return assignment;
}),
@@ -551,6 +565,9 @@ export const allocationRouter = createTRPCRouter({
projectId: updated.projectId,
resourceId: updated.resourceId,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, updated.projectId);
return updated;
}),
@@ -585,6 +602,9 @@ export const allocationRouter = createTRPCRouter({
});
emitAllocationDeleted(existing.id, existing.projectId);
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, existing.projectId);
return { success: true };
}),
@@ -607,6 +627,9 @@ export const allocationRouter = createTRPCRouter({
projectId: result.updatedDemandRequirement.projectId,
resourceId: null,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, result.assignment.projectId);
return result;
}),
@@ -623,6 +646,9 @@ export const allocationRouter = createTRPCRouter({
if (result.updatedAllocation) {
emitAllocationUpdated(result.updatedAllocation);
}
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, result.createdAllocation.projectId as string);
return result;
}),
@@ -665,6 +691,9 @@ export const allocationRouter = createTRPCRouter({
projectId: updated.projectId,
resourceId: updated.resourceId,
});
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, updated.projectId);
return updated;
}),
@@ -699,6 +728,9 @@ export const allocationRouter = createTRPCRouter({
});
emitAllocationDeleted(existing.id, existing.projectId);
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, existing.projectId);
return { success: true };
}),
@@ -726,6 +758,9 @@ export const allocationRouter = createTRPCRouter({
});
emitAllocationDeleted(existing.entry.id, existing.projectId);
void invalidateDashboardCache();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, existing.projectId);
return { success: true };
}),
@@ -760,6 +795,13 @@ export const allocationRouter = createTRPCRouter({
for (const a of existing) {
emitAllocationDeleted(a.entry.id, a.projectId);
}
void invalidateDashboardCache();
// Check budget thresholds for each affected project
const affectedProjectIds = [...new Set(existing.map((a) => a.projectId))];
for (const pid of affectedProjectIds) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, pid);
}
return { count: existing.length };
}),
@@ -804,6 +846,13 @@ export const allocationRouter = createTRPCRouter({
for (const a of updated) {
emitAllocationUpdated({ id: a.id, projectId: a.projectId, resourceId: a.resourceId });
}
void invalidateDashboardCache();
// Check budget thresholds for each affected project
const affectedProjectIds = [...new Set(updated.map((a) => a.projectId))];
for (const pid of affectedProjectIds) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void checkBudgetThresholds(ctx.db as any, pid);
}
return { count: updated.length };
}),