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:
@@ -8,9 +8,20 @@ import {
|
||||
getDashboardTopValueResources,
|
||||
} from "@planarchy/application";
|
||||
import { anonymizeResources, getAnonymizationDirectory } from "../lib/anonymization.js";
|
||||
import { cacheGet, cacheSet } from "../lib/cache.js";
|
||||
|
||||
const DEFAULT_TTL = 60; // seconds
|
||||
|
||||
export const dashboardRouter = createTRPCRouter({
|
||||
getOverview: protectedProcedure.query(({ ctx }) => getDashboardOverview(ctx.db)),
|
||||
getOverview: protectedProcedure.query(async ({ ctx }) => {
|
||||
const cacheKey = "overview";
|
||||
const cached = await cacheGet<Awaited<ReturnType<typeof getDashboardOverview>>>(cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
const result = await getDashboardOverview(ctx.db);
|
||||
await cacheSet(cacheKey, result, DEFAULT_TTL);
|
||||
return result;
|
||||
}),
|
||||
|
||||
getPeakTimes: protectedProcedure
|
||||
.input(
|
||||
@@ -21,27 +32,40 @@ export const dashboardRouter = createTRPCRouter({
|
||||
groupBy: z.enum(["project", "chapter", "resource"]).default("project"),
|
||||
}),
|
||||
)
|
||||
.query(({ ctx, input }) =>
|
||||
getDashboardPeakTimes(ctx.db, {
|
||||
.query(async ({ ctx, input }) => {
|
||||
const cacheKey = `peakTimes:${input.startDate}:${input.endDate}:${input.granularity}:${input.groupBy}`;
|
||||
const cached = await cacheGet<Awaited<ReturnType<typeof getDashboardPeakTimes>>>(cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
const result = await getDashboardPeakTimes(ctx.db, {
|
||||
startDate: new Date(input.startDate),
|
||||
endDate: new Date(input.endDate),
|
||||
granularity: input.granularity,
|
||||
groupBy: input.groupBy,
|
||||
}),
|
||||
),
|
||||
});
|
||||
await cacheSet(cacheKey, result, DEFAULT_TTL);
|
||||
return result;
|
||||
}),
|
||||
|
||||
getTopValueResources: protectedProcedure
|
||||
.input(z.object({ limit: z.number().int().min(1).max(50).default(10) }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const userRole =
|
||||
(ctx.session.user as { role?: string } | undefined)?.role ?? "USER";
|
||||
const cacheKey = `topValue:${input.limit}:${userRole}`;
|
||||
const cached = await cacheGet<Awaited<ReturnType<typeof anonymizeResources>>>(cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
const [resources, directory] = await Promise.all([
|
||||
getDashboardTopValueResources(ctx.db, {
|
||||
limit: input.limit,
|
||||
userRole:
|
||||
(ctx.session.user as { role?: string } | undefined)?.role ?? "USER",
|
||||
userRole,
|
||||
}),
|
||||
getAnonymizationDirectory(ctx.db),
|
||||
]);
|
||||
return anonymizeResources(resources, directory);
|
||||
const result = anonymizeResources(resources, directory);
|
||||
await cacheSet(cacheKey, result, DEFAULT_TTL);
|
||||
return result;
|
||||
}),
|
||||
|
||||
getDemand: protectedProcedure
|
||||
@@ -52,13 +76,19 @@ export const dashboardRouter = createTRPCRouter({
|
||||
groupBy: z.enum(["project", "person", "chapter"]).default("project"),
|
||||
}),
|
||||
)
|
||||
.query(({ ctx, input }) =>
|
||||
getDashboardDemand(ctx.db, {
|
||||
.query(async ({ ctx, input }) => {
|
||||
const cacheKey = `demand:${input.startDate}:${input.endDate}:${input.groupBy}`;
|
||||
const cached = await cacheGet<Awaited<ReturnType<typeof getDashboardDemand>>>(cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
const result = await getDashboardDemand(ctx.db, {
|
||||
startDate: new Date(input.startDate),
|
||||
endDate: new Date(input.endDate),
|
||||
groupBy: input.groupBy,
|
||||
}),
|
||||
),
|
||||
});
|
||||
await cacheSet(cacheKey, result, DEFAULT_TTL);
|
||||
return result;
|
||||
}),
|
||||
|
||||
getChargeabilityOverview: controllerProcedure
|
||||
.input(
|
||||
@@ -71,6 +101,15 @@ export const dashboardRouter = createTRPCRouter({
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const cacheKey = `chargeability:${input.includeProposed}:${input.topN}:${input.watchlistThreshold}:${(input.countryIds ?? []).join(",")}:${input.departed ?? ""}`;
|
||||
type ChargeResult = Awaited<ReturnType<typeof getDashboardChargeabilityOverview>>;
|
||||
const cached = await cacheGet<{
|
||||
top: unknown[];
|
||||
watchlist: unknown[];
|
||||
[key: string]: unknown;
|
||||
}>(cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
const [overview, directory] = await Promise.all([
|
||||
getDashboardChargeabilityOverview(ctx.db, {
|
||||
includeProposed: input.includeProposed,
|
||||
@@ -82,10 +121,12 @@ export const dashboardRouter = createTRPCRouter({
|
||||
getAnonymizationDirectory(ctx.db),
|
||||
]);
|
||||
|
||||
return {
|
||||
const result = {
|
||||
...overview,
|
||||
top: anonymizeResources(overview.top, directory),
|
||||
watchlist: anonymizeResources(overview.watchlist, directory),
|
||||
};
|
||||
await cacheSet(cacheKey, result, DEFAULT_TTL);
|
||||
return result;
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user