/** * Position publishability โ€” the pure rule behind B4's requirements editor * (ARCHITECTURE ยง4.3 rule 4). * * A position with no `is_core` skill cannot be published: if every skill on a * position is non-core, "anyone can fill it" becomes the rule by accident. The * gate lives here โ€” a single auditable predicate the route calls โ€” so the rule * and the code cannot drift. */ export interface PositionSkillInput { isCore?: boolean; weight?: number; } /** * A position is publishable when at least one of its skills is core. Core * skills hard-gate a solo assignment; without one there is nothing that * distinguishes a qualified operator from anyone. */ export function isPublishable(skills: readonly PositionSkillInput[]): boolean { return skills.some((skill) => skill.isCore === true); } /** * Validate a requirements payload before it hits the DB. Returns a list of * human-readable problems (empty when valid). Keeps the route thin and the * rules testable in isolation. * * - weight must be an integer in 1..5 * - a requested `published: true` requires at least one core skill */ export function validateRequirements(params: { skills: readonly PositionSkillInput[]; published?: boolean; }): string[] { const problems: string[] = []; const { skills, published } = params; skills.forEach((skill, i) => { const weight = skill.weight as number | undefined; if (weight === undefined) return; if (!Number.isInteger(weight) || weight < 1 || weight > 5) { problems.push(`skill[${i}].weight must be an integer from 1 to 5`); } }); if (published === true && !isPublishable(skills)) { problems.push("a published position needs at least one core skill"); } return problems; }