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:
@@ -4,11 +4,6 @@ const dateFormatter = new Intl.DateTimeFormat("de-AT", {
|
||||
year: "numeric",
|
||||
});
|
||||
|
||||
const eurFormatter = new Intl.NumberFormat("de-AT", {
|
||||
style: "currency",
|
||||
currency: "EUR",
|
||||
});
|
||||
|
||||
export function fmtDate(date: string | Date | null | undefined): string {
|
||||
if (!date) return "–";
|
||||
const d = typeof date === "string" ? new Date(date) : date;
|
||||
@@ -16,11 +11,6 @@ export function fmtDate(date: string | Date | null | undefined): string {
|
||||
return dateFormatter.format(d);
|
||||
}
|
||||
|
||||
export function fmtEUR(amount: number | null | undefined): string {
|
||||
if (amount === null || amount === undefined) return "••• (ausgeblendet)";
|
||||
return eurFormatter.format(amount);
|
||||
}
|
||||
|
||||
export function initials(firstName: string, lastName: string): string {
|
||||
const a = firstName.trim().charAt(0).toUpperCase();
|
||||
const b = lastName.trim().charAt(0).toUpperCase();
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function loadOpenPositions(supabase: SupabaseClient<Database>): Pro
|
||||
new Set((positions ?? []).map((p) => p.reports_to_employee_id).filter((id): id is string => Boolean(id)))
|
||||
);
|
||||
const { data: managers } = managerIds.length
|
||||
? await supabase.from("employees_directory").select("id, first_name, last_name").in("id", managerIds)
|
||||
? await supabase.from("employees").select("id, first_name, last_name").in("id", managerIds)
|
||||
: { data: [] as { id: string; first_name: string; last_name: string }[] };
|
||||
const managerNameById = new Map((managers ?? []).map((m) => [m.id, `${m.first_name} ${m.last_name}`]));
|
||||
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Hand-written to match supabase/schema.sql (no DB connection string available to
|
||||
// run `supabase gen types typescript` in this environment — regenerate from the
|
||||
// live project once you have the Supabase CLI linked).
|
||||
// Hand-written to match supabase/schema.sql + supabase/migrations/*.sql (no DB
|
||||
// connection string available to run `supabase gen types typescript` in this
|
||||
// environment — regenerate from the live project once you have the Supabase
|
||||
// CLI linked).
|
||||
|
||||
export type EmploymentStatus = "Aktiv" | "Karenz" | "Geplant" | "Ausgetreten";
|
||||
export type EmploymentType = "Vollzeit" | "Teilzeit";
|
||||
@@ -8,7 +9,10 @@ export type ContractType = "unbefristet" | "befristet";
|
||||
export type PaygradeType = "A" | "B" | "C" | "D" | "E" | "F";
|
||||
export type SourceType = "Intern" | "Extern";
|
||||
export type GenderType = "m" | "w";
|
||||
export type ProfileRole = "hr_admin" | "manager";
|
||||
// Single HR-only role (see docs/decisions/0001-hr-only-access.md). Kept as a
|
||||
// union (not a string literal) so a future hr_admin/hr_user split, if ever
|
||||
// technically required, is a type-level addition, not a rewrite.
|
||||
export type ProfileRole = "hr";
|
||||
export type HistoryEventType =
|
||||
| "Eintritt"
|
||||
| "Beförderung"
|
||||
@@ -23,6 +27,14 @@ export type HistoryEventType =
|
||||
| "Rückkehr";
|
||||
export type PositionStatus = "open" | "filled";
|
||||
export type ReorgMoveKind = "emp" | "team" | "abt" | "dept";
|
||||
export type PendingChangeType =
|
||||
| "transfer"
|
||||
| "promotion"
|
||||
| "karenz_start"
|
||||
| "karenz_return"
|
||||
| "contract_change"
|
||||
| "reorg";
|
||||
export type PendingChangeStatus = "pending" | "applied" | "cancelled";
|
||||
|
||||
// @supabase/postgrest-js requires every table/view to carry a Relationships
|
||||
// array (used for typed embedded selects) — left empty since no code in this
|
||||
@@ -53,9 +65,36 @@ export type Database = {
|
||||
Update: Partial<{ id: string; name: string; country: string }>;
|
||||
};
|
||||
profiles: NoRelationships & {
|
||||
Row: { id: string; email: string; full_name: string | null; role: ProfileRole; created_at: string };
|
||||
Insert: { id: string; email: string; full_name?: string | null; role?: ProfileRole; created_at?: string };
|
||||
Update: Partial<{ id: string; email: string; full_name: string | null; role: ProfileRole; created_at: string }>;
|
||||
Row: {
|
||||
id: string;
|
||||
email: string;
|
||||
full_name: string | null;
|
||||
role: ProfileRole;
|
||||
is_active: boolean;
|
||||
created_by: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
Insert: {
|
||||
id: string;
|
||||
email: string;
|
||||
full_name?: string | null;
|
||||
role?: ProfileRole;
|
||||
is_active?: boolean;
|
||||
created_by?: string | null;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
Update: Partial<{
|
||||
id: string;
|
||||
email: string;
|
||||
full_name: string | null;
|
||||
role: ProfileRole;
|
||||
is_active: boolean;
|
||||
created_by: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>;
|
||||
};
|
||||
employees: NoRelationships & {
|
||||
Row: {
|
||||
@@ -80,7 +119,8 @@ export type Database = {
|
||||
is_lead: boolean;
|
||||
employment_type: EmploymentType;
|
||||
weekly_hours: number;
|
||||
monthly_salary_gross: number;
|
||||
/** @deprecated Salary is out of MVP scope; column kept only for pre-existing data. */
|
||||
monthly_salary_gross: number | null;
|
||||
contract_type: ContractType;
|
||||
contract_end_date: string | null;
|
||||
paygrade: PaygradeType;
|
||||
@@ -89,6 +129,7 @@ export type Database = {
|
||||
entry_date: string;
|
||||
exit_date: string | null;
|
||||
exit_reason: string | null;
|
||||
karenz_start_date: string | null;
|
||||
karenz_return_date: string | null;
|
||||
avatar_color: string | null;
|
||||
created_at: string;
|
||||
@@ -115,7 +156,6 @@ export type Database = {
|
||||
is_lead?: boolean;
|
||||
employment_type?: EmploymentType;
|
||||
weekly_hours?: number;
|
||||
monthly_salary_gross: number;
|
||||
contract_type?: ContractType;
|
||||
contract_end_date?: string | null;
|
||||
paygrade?: PaygradeType;
|
||||
@@ -124,6 +164,7 @@ export type Database = {
|
||||
entry_date: string;
|
||||
exit_date?: string | null;
|
||||
exit_reason?: string | null;
|
||||
karenz_start_date?: string | null;
|
||||
karenz_return_date?: string | null;
|
||||
avatar_color?: string | null;
|
||||
created_at?: string;
|
||||
@@ -138,6 +179,7 @@ export type Database = {
|
||||
event_date: string;
|
||||
event_type: HistoryEventType;
|
||||
description: string;
|
||||
reorg_scenario_id: string | null;
|
||||
created_at: string;
|
||||
};
|
||||
Insert: {
|
||||
@@ -146,6 +188,7 @@ export type Database = {
|
||||
event_date: string;
|
||||
event_type: HistoryEventType;
|
||||
description: string;
|
||||
reorg_scenario_id?: string | null;
|
||||
created_at?: string;
|
||||
};
|
||||
Update: Partial<Database["public"]["Tables"]["employee_history"]["Insert"]>;
|
||||
@@ -240,47 +283,35 @@ export type Database = {
|
||||
Insert: { id?: string; scenario_id: string; kind: ReorgMoveKind; payload: Record<string, unknown> };
|
||||
Update: Partial<Database["public"]["Tables"]["reorg_moves"]["Insert"]>;
|
||||
};
|
||||
};
|
||||
Views: {
|
||||
employees_directory: NoRelationships & {
|
||||
pending_org_changes: NoRelationships & {
|
||||
Row: {
|
||||
id: string;
|
||||
personnel_number: number;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
gender: GenderType;
|
||||
birth_date: string;
|
||||
sv_nummer: string | null;
|
||||
nationality: string;
|
||||
address: string | null;
|
||||
address_country: string | null;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
team_id: string | null;
|
||||
division_id: string;
|
||||
job_title: string;
|
||||
location_id: string;
|
||||
manager_id: string | null;
|
||||
org_level: number;
|
||||
is_lead: boolean;
|
||||
employment_type: EmploymentType;
|
||||
weekly_hours: number;
|
||||
monthly_salary_gross: number | null; // masked to null for non-admin sessions
|
||||
contract_type: ContractType;
|
||||
contract_end_date: string | null;
|
||||
paygrade: PaygradeType;
|
||||
source: SourceType;
|
||||
status: EmploymentStatus;
|
||||
entry_date: string;
|
||||
exit_date: string | null;
|
||||
exit_reason: string | null;
|
||||
karenz_return_date: string | null;
|
||||
avatar_color: string | null;
|
||||
employee_id: string;
|
||||
change_type: PendingChangeType;
|
||||
effective_date: string;
|
||||
payload: Record<string, unknown>;
|
||||
reorg_scenario_id: string | null;
|
||||
status: PendingChangeStatus;
|
||||
created_by: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
applied_at: string | null;
|
||||
};
|
||||
Insert: {
|
||||
id?: string;
|
||||
employee_id: string;
|
||||
change_type: PendingChangeType;
|
||||
effective_date: string;
|
||||
payload: Record<string, unknown>;
|
||||
reorg_scenario_id?: string | null;
|
||||
status?: PendingChangeStatus;
|
||||
created_by?: string | null;
|
||||
created_at?: string;
|
||||
applied_at?: string | null;
|
||||
};
|
||||
Update: Partial<Database["public"]["Tables"]["pending_org_changes"]["Insert"]>;
|
||||
};
|
||||
};
|
||||
Views: Record<string, never>;
|
||||
Functions: {
|
||||
hire_employee: { Args: { payload: Record<string, unknown> }; Returns: string };
|
||||
terminate_employee: { Args: { payload: Record<string, unknown> }; Returns: void };
|
||||
@@ -295,6 +326,7 @@ export type Database = {
|
||||
staff_position_internally: { Args: { payload: Record<string, unknown> }; Returns: void };
|
||||
apply_reorg: { Args: { payload: Record<string, unknown> }; Returns: string };
|
||||
undo_reorg: { Args: { payload: Record<string, unknown> }; Returns: void };
|
||||
apply_due_pending_changes: { Args: Record<string, never>; Returns: number };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user