b0e55786c3
AI Assistant (HartBOT): - Chat panel with inline layout, session persistence, message history (up-arrow recall) - OpenAI function calling with 20+ tools (search, navigate, create/cancel allocations, update status) - RBAC-aware tool filtering, fuzzy search with word-level matching - Navigation actions (router.push) and data invalidation after mutations - Country/metro city/org unit/role filtering on resource search Demand Filling Enhancements: - Two-phase fill modal: plan multiple resources, then confirm & assign all at once - Availability preview per resource (available/partial/conflict days, existing bookings) - Coverage bar showing demand hours distribution across assigned resources - Fill demand from project detail page (new Assign button per demand) - Fixed: filled demands no longer shown on timeline, demand bars no longer overlap Budget per Role: - DemandRequirement.budgetCents field (schema + API + UI) - Project wizard step 3: budget input per role with allocation summary bar - Project detail: allocated vs booked budget per demand - Fill demand modal: role budget display with cost estimates - AllocationModal: budget field for demand editing Project Favorites: - User.favoriteProjectIds (JSONB) with toggle API - Star button on projects list and detail page (optimistic updates) - "My Projects" dashboard widget (favorites + responsible person projects) Project Management: - Edit project from detail page (ProjectModal integration) - Edit demands from detail page (AllocationModal integration) - Admin-only project deletion (cascades assignments + demands) - Create user accounts from admin panel Timeline Fixes: - Country multi-select filter with backend support - URL param sync for same-page navigation (AI assistant integration) - Demand lane stacking (no more overlapping bars) - Single-day booking resize handles (always visible, min 6px) - Single-day resize allowed (start === end) - "All Clients" toggle (select all / deselect all) Other Fixes: - crypto.randomUUID fallback for non-secure contexts - Chat message limit raised (200 max, client sends last 40) - Status dropdown portal (no longer clipped by table overflow) - Cents display restored in budget views (2 decimal places) - Allocations grouped view with project sub-groups (collapsed by default) - Server-side resource search for project wizard (no 500 limit) Co-Authored-By: claude-flow <ruv@ruv.net>
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import type { PrismaClient, Prisma } from "@planarchy/db";
|
|
import { type CreateDemandRequirementInput } from "@planarchy/shared";
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
type DbClient = PrismaClient | Prisma.TransactionClient;
|
|
|
|
export const DEMAND_REQUIREMENT_RELATIONS_INCLUDE = {
|
|
project: { select: { id: true, name: true, shortCode: true } },
|
|
roleEntity: { select: { id: true, name: true, color: true } },
|
|
} as const;
|
|
|
|
export type DemandRequirementWithRelations = Prisma.DemandRequirementGetPayload<{
|
|
include: typeof DEMAND_REQUIREMENT_RELATIONS_INCLUDE;
|
|
}>;
|
|
|
|
export async function createDemandRequirement(
|
|
db: DbClient,
|
|
input: CreateDemandRequirementInput,
|
|
): Promise<DemandRequirementWithRelations> {
|
|
const project = await db.project.findUnique({ where: { id: input.projectId } });
|
|
if (!project) {
|
|
throw new TRPCError({ code: "NOT_FOUND", message: "Project not found" });
|
|
}
|
|
|
|
const demandRequirement = await db.demandRequirement.create({
|
|
data: {
|
|
projectId: input.projectId,
|
|
startDate: input.startDate,
|
|
endDate: input.endDate,
|
|
hoursPerDay: input.hoursPerDay,
|
|
percentage: input.percentage,
|
|
role: input.role ?? null,
|
|
roleId: input.roleId ?? null,
|
|
headcount: input.headcount ?? 1,
|
|
budgetCents: input.budgetCents ?? 0,
|
|
status: input.status,
|
|
metadata: input.metadata as unknown as Prisma.InputJsonValue,
|
|
},
|
|
include: DEMAND_REQUIREMENT_RELATIONS_INCLUDE,
|
|
});
|
|
|
|
await db.auditLog.create({
|
|
data: {
|
|
entityType: "DemandRequirement",
|
|
entityId: demandRequirement.id,
|
|
action: "CREATE",
|
|
changes: { after: demandRequirement } as unknown as Prisma.InputJsonValue,
|
|
},
|
|
});
|
|
|
|
return demandRequirement;
|
|
}
|