Employee names now read "Winkler, Hannah" wherever a person appears in a list, a table, a heading or a tree node. That is the order a personnel list is kept in, it is the order people are looked up in, and it finally matches the sorting — the employee list has always been ordered by surname, which made an alphabetical page look unsorted. The name was being assembled inline in about twenty places. A rename that catches half of them is worse than none, so it now goes through fmtName in lib/format.ts and every display site calls it. Sentences keep the natural order: "Hannah Winkler wurde versetzt" reads like German, "Winkler, Hannah wurde versetzt" reads like a form. So the toasts are unchanged and only labels moved. Two things the change would have quietly broken: The org chart's own filter matched against "first last". It now matches either order, with or without the comma, so typing what you see works and so does typing what you remember. The print model sorted by the last word of the composed name, which happened to be the surname and is now the first name — every printed unit would have come out sorted by first name. It sorts on the surname field itself now, which is what it meant all along. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import type { Tx } from "./db";
|
|
import type { Database } from "./supabase/types";
|
|
import { fmtName } from "./format";
|
|
|
|
export type OpenNote = Database["public"]["Tables"]["employee_notes"]["Row"] & {
|
|
employeeName: string;
|
|
};
|
|
|
|
// „Meine Notizen" (Topbar-Glocke): das geteilte, mitarbeiterübergreifende
|
|
// Postfach aller noch nicht erledigten HR-Notizen — unabhängig davon, wer sie
|
|
// verfasst hat oder zu wem sie gehören (mit Nutzer abgestimmt).
|
|
//
|
|
// Früher zwei Abfragen, in JavaScript zusammengeführt, weil die API-Schicht
|
|
// für eine einzelne verschachtelte Abfrage keine Verknüpfung anbot. Am
|
|
// direkten Zugang ist es schlicht ein Join.
|
|
export async function loadOpenNotes(tx: Tx): Promise<OpenNote[]> {
|
|
const rows = await tx
|
|
.selectFrom("employee_notes as n")
|
|
.leftJoin("employees as e", "e.id", "n.employee_id")
|
|
.selectAll("n")
|
|
.select(["e.first_name", "e.last_name"])
|
|
.where("n.done", "=", false)
|
|
.orderBy("n.created_at", "desc")
|
|
.execute();
|
|
|
|
return rows.map((row) => {
|
|
const { first_name, last_name, ...note } = row;
|
|
return {
|
|
...(note as Database["public"]["Tables"]["employee_notes"]["Row"]),
|
|
employeeName: first_name && last_name ? fmtName(first_name, last_name) : "Unbekannt",
|
|
};
|
|
});
|
|
}
|