92a982b151
Engine (packages/engine): - calculateShoringRatio() pure function: onshore/offshore hours, country breakdown, threshold check, weighted by hours not headcount - 12 unit tests: empty, 100% onshore/offshore, mixed ratios, custom threshold, case-insensitive, unknown country, FTE weighting Schema: - Project.shoringThreshold (default 55%) — per-project configurable - Project.onshoreCountryCode (default "DE") — configurable onshore country API (project router): - getShoringRatio query: loads assignments with resource.country, computes ratio, returns full breakdown - update mutation: accepts shoringThreshold + onshoreCountryCode UI: - ShoringIndicator: stacked horizontal bar with country segments, severity badge (green/yellow/red), hover tooltip, dark theme - ShoringBadge: mini colored dot + % for project list column - ProjectModal: "Max Offshore %" number input - Project detail: indicator after budget status card - Project list: "Shoring" column (default hidden, toggleable) AI Assistant: - get_shoring_ratio tool: human-readable breakdown with threshold alert Colors: green (<threshold-10), yellow (threshold-10 to threshold), red (>=threshold) Default: 55% offshore threshold, "DE" as onshore country Co-Authored-By: claude-flow <ruv@ruv.net>
50 lines
2.1 KiB
TypeScript
50 lines
2.1 KiB
TypeScript
import { z } from "zod";
|
|
import { AllocationType, OrderType, ProjectStatus } from "../types/enums.js";
|
|
|
|
export const StaffingRequirementSchema = z.object({
|
|
id: z.string().uuid().default(() => crypto.randomUUID()),
|
|
role: z.string().min(1).max(200),
|
|
requiredSkills: z.array(z.string()),
|
|
preferredSkills: z.array(z.string()).optional(),
|
|
hoursPerDay: z.number().min(0).max(24),
|
|
headcount: z.number().int().min(1),
|
|
startDate: z.string().optional(),
|
|
endDate: z.string().optional(),
|
|
notes: z.string().optional(),
|
|
chapter: z.string().optional(),
|
|
});
|
|
|
|
// Base object schema — used for .partial() in UpdateProjectSchema
|
|
export const CreateProjectBaseSchema = z.object({
|
|
shortCode: z.string().min(1).max(20).regex(/^[A-Z0-9_-]+$/, "Must be uppercase alphanumeric"),
|
|
name: z.string().min(1).max(500),
|
|
orderType: z.nativeEnum(OrderType),
|
|
allocationType: z.nativeEnum(AllocationType),
|
|
winProbability: z.number().int().min(0).max(100).default(100),
|
|
budgetCents: z.number().int().min(0),
|
|
startDate: z.coerce.date(),
|
|
endDate: z.coerce.date(),
|
|
staffingReqs: z.array(StaffingRequirementSchema).default([]),
|
|
dynamicFields: z.record(z.string(), z.unknown()).default({}),
|
|
blueprintId: z.string().optional(),
|
|
status: z.nativeEnum(ProjectStatus).default(ProjectStatus.DRAFT),
|
|
responsiblePerson: z.string().min(1, "Responsible person is required").max(200),
|
|
color: z.string().regex(/^#[0-9a-fA-F]{6}$/, "Must be a hex color like #3b82f6").optional(),
|
|
utilizationCategoryId: z.string().optional(),
|
|
clientId: z.string().optional(),
|
|
coverImageUrl: z.string().optional(),
|
|
shoringThreshold: z.number().int().min(0).max(100).optional(),
|
|
onshoreCountryCode: z.string().min(2).max(3).optional(),
|
|
});
|
|
|
|
// Full schema with date-range validation
|
|
export const CreateProjectSchema = CreateProjectBaseSchema.refine(
|
|
(data) => data.endDate >= data.startDate,
|
|
{ message: "End date must be after start date", path: ["endDate"] },
|
|
);
|
|
|
|
export const UpdateProjectSchema = CreateProjectBaseSchema.partial();
|
|
|
|
export type CreateProjectInput = z.infer<typeof CreateProjectSchema>;
|
|
export type UpdateProjectInput = z.infer<typeof UpdateProjectSchema>;
|