Files
alpenwerk-hr/components/hire/types.ts
Maximilian Stubhan 9d754359e0 Enter the personnel number, tell the two kinds of company car apart, record who to call
Three requests from use, one of which changes the schema's mind about
something.

The personnel number is no longer issued. It was GENERATED ALWAYS AS
IDENTITY, which refuses a supplied value outright — but it has to match Loga
and Interflex, and a number this application invents is unknown there, so the
same person ends up with two. Identity dropped, entered everywhere instead:
in the wizard, in the import, and validated against a duplicate with a
message that names the number.

Worth stating plainly: the column had no unique constraint. The identity
prevented collisions as a side effect, and once the value comes from outside
that side effect is gone. The constraint is the point now, and it was
missing.

Company cars distinguish Verbrenner from Elektro, tied to has_dienstwagen by
a CHECK so "E-KFZ" cannot appear against someone without a car. The list
filters on it — with, without, only electric, only combustion — which is the
question the report was really about; it was answerable before only through
an export and manual work.

Emergency contact is name, phone and relationship. Relationship stays free
text: the examples given — Gattin/Gatte, Schwester/Bruder, Freund — are not
a list that closes without telling someone their arrangement does not count.
Name and phone are all-or-nothing, in the database and in both forms: a name
without a number helps nobody, a number without a name does not say who
answers.

Two mistakes of mine on the way, both caught by checks I had written into
the migrations rather than by me:

  - The first CHECK on the car type would have permitted exactly the case it
    was written against. `art in (…)` yields NULL rather than false when the
    column is null, and a CHECK counts NULL as satisfied. It needs an
    explicit `is not null` in front.
  - The constraint was added before the backfill, so it rejected every
    existing row with a car.

Existing cars are recorded as Verbrenner, which is an assumption — but a
visible one: "Elektro" appears nowhere nobody confirmed it.

hire_employee and change_employee_data both had to learn the new columns.
They name their columns one by one, and what is missing there is dropped in
silence — the interface would have collected the fields and thrown them
away, which is what happened to the email address this morning.

Verified against the live database, all rolled back: a hire without a number
is refused, a duplicate is refused naming it, a freely chosen one goes
through; E-KFZ plus contact arrive intact; a contact without a phone is
refused. A change records both, with before and after in the audit detail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 21:27:00 +02:00

78 lines
2.2 KiB
TypeScript

import type { CollectiveAgreement, ContractType, DienstwagenArt, EmploymentType, GenderType, PaygradeType, Weekday, WorkerType } from "@/lib/supabase/types";
// The spec's hire wizard field list (§4.4) omits Geschlecht and Standort even
// though both are NOT NULL on employees — added here (defaults keep them
// effectively "free" for the user, same treatment as the karenz-start gap).
export type HireDraftData = {
/**
* Eingabe, nicht Vergabe.
*
* Muss mit Loga und Interflex übereinstimmen — als Zeichenkette geführt,
* weil ein leeres Zahlenfeld sonst als 0 im Entwurf landet.
*/
personnelNumber: string;
firstName: string;
lastName: string;
titlePrefix: string[];
titleSuffix: string[];
gender: GenderType;
birthDate: string;
svNummer: string;
email: string;
phone: string;
locationId: string;
positionId: string;
besetzung: "Intern" | "Extern" | "";
entryDate: string;
contractType: ContractType;
contractEndDate: string;
employmentType: EmploymentType;
weeklyHours: string;
paygrade: PaygradeType;
workerType: WorkerType;
collectiveAgreement: CollectiveAgreement;
workDays: Weekday[];
isBetriebsrat: boolean;
hasDienstwagen: boolean;
/** Nur ausgewertet, wenn hasDienstwagen gesetzt ist — so will es der CHECK. */
dienstwagenArt: DienstwagenArt;
emergencyContactName: string;
emergencyContactPhone: string;
emergencyContactRelation: string;
isLateraleFuehrung: boolean;
isCLevel: boolean;
};
export const EMPTY_HIRE_DRAFT: HireDraftData = {
personnelNumber: "",
firstName: "",
lastName: "",
titlePrefix: [],
titleSuffix: [],
gender: "m",
birthDate: "",
svNummer: "",
email: "",
phone: "",
locationId: "",
positionId: "",
besetzung: "",
entryDate: "",
contractType: "unbefristet",
contractEndDate: "",
employmentType: "Vollzeit",
weeklyHours: "38.5",
paygrade: "B",
workerType: "Angestellte:r",
collectiveAgreement: "Handel",
workDays: ["Mo", "Di", "Mi", "Do", "Fr"],
isBetriebsrat: false,
hasDienstwagen: false,
dienstwagenArt: "Verbrenner",
emergencyContactName: "",
emergencyContactPhone: "",
emergencyContactRelation: "",
isLateraleFuehrung: false,
isCLevel: false,
};