Consolidation pass: HR-only access, effective-dated mutations, data integrity guards, test suite

Reworks the app from a two-role (hr_admin/manager) model to a single
HR-only role gated by profiles.is_active, fixes transfer/promote/karenz/
reorg RPCs to actually defer future-dated changes via a new
pending_org_changes table instead of writing them immediately (applied
by a daily Vercel Cron route), makes reorg undo append-only instead of
deleting history, adds Karenz-return and history-date integrity guards,
deprecates the salary column, and adds explicit schema grants + perf
indexes needed to run against a fresh (non-hosted) Postgres instance.

Adds vitest unit + integration test suites (the latter against a real
local Supabase instance) covering all of the above, plus lint/typecheck/
build wiring (`npm run check`).
This commit is contained in:
2026-07-14 20:32:20 +02:00
parent 4299277af0
commit 901c5c426e
67 changed files with 4765 additions and 286 deletions

View File

@@ -3,7 +3,6 @@ export type Measure =
| "fte"
| "hires"
| "exits"
| "avg_salary"
| "parttime_rate"
| "avg_age"
| "avg_tenure"
@@ -26,7 +25,6 @@ export const MEASURE_LABELS: Record<Measure, string> = {
fte: "FTE",
hires: "Eintritte",
exits: "Austritte",
avg_salary: "Ø Bruttogehalt",
parttime_rate: "Teilzeitquote",
avg_age: "Ø Alter",
avg_tenure: "Ø Zugehörigkeit",
@@ -46,7 +44,7 @@ export const GROUP_LABELS: Record<GroupDimension, string> = {
paygrade: "Paygrade",
};
export const AVERAGE_MEASURES: Measure[] = ["avg_salary", "parttime_rate", "avg_age", "avg_tenure", "female_share"];
export const AVERAGE_MEASURES: Measure[] = ["parttime_rate", "avg_age", "avg_tenure", "female_share"];
export const DATE_SCOPED_MEASURES: Measure[] = ["hires", "exits"];
export type ReportEmployee = {
@@ -63,7 +61,6 @@ export type ReportEmployee = {
entry_date: string;
exit_date: string | null;
weekly_hours: number;
monthly_salary_gross: number | null;
source: string;
paygrade: string;
birth_date: string;
@@ -127,10 +124,6 @@ export function measureValue(rows: ReportEmployee[], measure: Measure): number {
return rows.length;
case "fte":
return rows.reduce((s, e) => s + e.weekly_hours / 38.5, 0);
case "avg_salary": {
const withSalary = rows.filter((e) => e.monthly_salary_gross != null);
return withSalary.length ? withSalary.reduce((s, e) => s + (e.monthly_salary_gross ?? 0), 0) / withSalary.length : 0;
}
case "parttime_rate":
return (rows.filter((e) => e.employment_type === "Teilzeit").length / rows.length) * 100;
case "avg_age":
@@ -194,7 +187,7 @@ export function aggregateReport(
export const REPORT_PRESETS: { name: string; measure: Measure; group: GroupDimension; split?: GroupDimension }[] = [
{ name: "Headcount nach Bereich", measure: "headcount", group: "division" },
{ name: "Frauenanteil nach Bereich", measure: "female_share", group: "division" },
{ name: "Ø Gehalt nach Paygrade", measure: "avg_salary", group: "paygrade" },
{ name: "Headcount nach Paygrade", measure: "headcount", group: "paygrade" },
{ name: "Teilzeitquote nach Standort", measure: "parttime_rate", group: "location" },
{ name: "Eintritte nach Bereich", measure: "hires", group: "division" },
{ name: "Austritte nach Abteilung", measure: "exits", group: "department" },