Files
CapaKraken/packages/shared/src/schemas/allocation.schema.ts
T
Hartmut b0e55786c3 feat: AI assistant (HartBOT), demand filling, budget-per-role, project favorites, and UX improvements
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>
2026-03-16 15:31:48 +01:00

113 lines
4.4 KiB
TypeScript

import { z } from "zod";
import { AllocationStatus } from "../types/enums.js";
export const CreateAllocationBaseSchema = z.object({
resourceId: z.string().optional(),
projectId: z.string(),
startDate: z.coerce.date(),
endDate: z.coerce.date(),
hoursPerDay: z.number().min(0).max(24),
percentage: z.number().min(0).max(100),
role: z.string().max(200).optional(),
roleId: z.string().optional(),
headcount: z.number().int().min(1).default(1),
budgetCents: z.number().int().min(0).optional(),
status: z.nativeEnum(AllocationStatus).default(AllocationStatus.PROPOSED),
metadata: z.record(z.string(), z.unknown()).default({}),
});
export const CreateDemandRequirementBaseSchema = z.object({
projectId: z.string(),
startDate: z.coerce.date(),
endDate: z.coerce.date(),
hoursPerDay: z.number().min(0).max(24),
percentage: z.number().min(0).max(100),
role: z.string().max(200).optional(),
roleId: z.string().optional(),
headcount: z.number().int().min(1).default(1),
budgetCents: z.number().int().min(0).optional(),
status: z.nativeEnum(AllocationStatus).default(AllocationStatus.PROPOSED),
metadata: z.record(z.string(), z.unknown()).default({}),
});
export const CreateAssignmentBaseSchema = z.object({
demandRequirementId: z.string().optional(),
resourceId: z.string(),
projectId: z.string(),
startDate: z.coerce.date(),
endDate: z.coerce.date(),
hoursPerDay: z.number().min(0).max(24),
percentage: z.number().min(0).max(100),
role: z.string().max(200).optional(),
roleId: z.string().optional(),
dailyCostCents: z.number().int().min(0).optional(),
status: z.nativeEnum(AllocationStatus).default(AllocationStatus.PROPOSED),
metadata: z.record(z.string(), z.unknown()).default({}),
});
export const CreateAllocationSchema = CreateAllocationBaseSchema.refine(
(data) => data.endDate >= data.startDate,
{ message: "End date must be after start date", path: ["endDate"] },
);
export const UpdateAllocationSchema = CreateAllocationBaseSchema.partial();
export const CreateDemandRequirementSchema = CreateDemandRequirementBaseSchema.refine(
(data) => data.endDate >= data.startDate,
{ message: "End date must be after start date", path: ["endDate"] },
);
export const UpdateDemandRequirementSchema = CreateDemandRequirementBaseSchema.partial();
export const CreateAssignmentSchema = CreateAssignmentBaseSchema.refine(
(data) => data.endDate >= data.startDate,
{ message: "End date must be after start date", path: ["endDate"] },
);
export const UpdateAssignmentSchema = CreateAssignmentBaseSchema.partial();
export const FillDemandRequirementSchema = z.object({
demandRequirementId: z.string(),
resourceId: z.string(),
hoursPerDay: z.number().min(0.5).max(24).optional(),
status: z.nativeEnum(AllocationStatus).optional(),
});
export const FillOpenDemandByAllocationSchema = z.object({
allocationId: z.string(),
resourceId: z.string(),
hoursPerDay: z.number().min(0.5).max(24).optional(),
status: z.nativeEnum(AllocationStatus).optional(),
});
export const ShiftProjectSchema = z
.object({
projectId: z.string(),
newStartDate: z.coerce.date(),
newEndDate: z.coerce.date(),
})
.refine((data) => data.newEndDate >= data.newStartDate, {
message: "New end date must be after new start date",
path: ["newEndDate"],
});
export const UpdateAllocationHoursSchema = z.object({
allocationId: z.string(),
hoursPerDay: z.number().min(0.5).max(24).optional(),
startDate: z.coerce.date().optional(),
endDate: z.coerce.date().optional(),
includeSaturday: z.boolean().optional(),
role: z.string().min(1).max(200).optional(),
});
export type CreateAllocationInput = z.infer<typeof CreateAllocationSchema>;
export type UpdateAllocationInput = z.infer<typeof UpdateAllocationSchema>;
export type CreateDemandRequirementInput = z.infer<typeof CreateDemandRequirementSchema>;
export type UpdateDemandRequirementInput = z.infer<typeof UpdateDemandRequirementSchema>;
export type CreateAssignmentInput = z.infer<typeof CreateAssignmentSchema>;
export type UpdateAssignmentInput = z.infer<typeof UpdateAssignmentSchema>;
export type FillDemandRequirementInput = z.infer<typeof FillDemandRequirementSchema>;
export type FillOpenDemandByAllocationInput = z.infer<typeof FillOpenDemandByAllocationSchema>;
export type ShiftProjectInput = z.infer<typeof ShiftProjectSchema>;
export type UpdateAllocationHoursInput = z.infer<typeof UpdateAllocationHoursSchema>;