Übergabestand 2026-10-14
Alpenwerk HR — HR-Stammdatenverwaltung Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte, Massenimport und ein lückenloser Nachweis jeder Änderung. Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der Datenbank, die Zugriffsschranke ist Row Level Security. Betrieb auf Windows Server: siehe deploy/windows/README.md. Sicherheitskonzept: docs/sicherheitskonzept.md.
This commit is contained in:
69
app/api/export/events/route.ts
Normal file
69
app/api/export/events/route.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { exportFilename, exportResponseHeaders, toCsv, toXlsx, type ExportColumn } from "@/lib/export";
|
||||
import {
|
||||
EVENT_TYPE_LABELS,
|
||||
parseEventDateParam,
|
||||
parseEventSubtype,
|
||||
parseEventType,
|
||||
type OrgLookups,
|
||||
type ReportEvent,
|
||||
} from "@/lib/reports";
|
||||
import { loadEventHistory, loadOrgLookups } from "@/lib/reports-data";
|
||||
import { requireHrUser } from "@/lib/auth/require-hr";
|
||||
import { withUser } from "@/lib/db";
|
||||
|
||||
// Full raw event-log dump — one row per employee_history entry in the
|
||||
// selected period (default: current year), every event type unless one is
|
||||
// picked, org columns resolved from each affected employee's current
|
||||
// placement (see loadEventHistory).
|
||||
export async function GET(request: NextRequest) {
|
||||
const gate = await requireHrUser();
|
||||
if ("denied" in gate) return gate.denied;
|
||||
|
||||
const params = request.nextUrl.searchParams;
|
||||
const format = params.get("format") === "xlsx" ? "xlsx" : "csv";
|
||||
const eventType = parseEventType(params.get("eventType"));
|
||||
|
||||
const { lookups, events } = await withUser(gate.userId, async (tx) => {
|
||||
const [{ lookups }, events] = await Promise.all([
|
||||
loadOrgLookups(tx),
|
||||
loadEventHistory(tx, {
|
||||
eventType: eventType ?? undefined,
|
||||
// Ohne diese Zeile exportierte die Schaltfläche neben der Auswertung
|
||||
// etwas anderes, als auf dem Bildschirm steht — die Einschränkung auf
|
||||
// die Beendigungsart fiele beim Export still weg.
|
||||
eventSubtype: parseEventSubtype(params.get("eventSubtype"), eventType) ?? undefined,
|
||||
division: params.get("division") ?? undefined,
|
||||
location: params.get("location") ?? undefined,
|
||||
from: parseEventDateParam(params.get("from")),
|
||||
to: parseEventDateParam(params.get("to")),
|
||||
}),
|
||||
]);
|
||||
return { lookups, events };
|
||||
});
|
||||
|
||||
const columns = eventExportColumns(lookups);
|
||||
const filename = exportFilename(`ereignisse-${eventType ?? "alle"}`, format);
|
||||
const body = format === "xlsx" ? await toXlsx(events, columns, "Ereignisse") : toCsv(events, columns);
|
||||
// TS 5.9's Uint8Array<ArrayBufferLike> vs DOM's BlobPart/ArrayBuffer<> generic
|
||||
// mismatch (microsoft/TypeScript#59417) — a real Uint8Array works fine here.
|
||||
return new NextResponse(new Blob([body as BlobPart]), { headers: exportResponseHeaders(filename, format) });
|
||||
}
|
||||
|
||||
function eventExportColumns(lookups: OrgLookups): ExportColumn<ReportEvent>[] {
|
||||
return [
|
||||
{ header: "Datum", get: (e) => e.event_date, kind: "date" },
|
||||
{ header: "Ereignistyp", get: (e) => EVENT_TYPE_LABELS[e.event_type] ?? e.event_type },
|
||||
// Beendigungsart bzw. Art der Langzeitabwesenheit. Leer bei allen
|
||||
// Ereignissen, die keinen Untertyp kennen — eine Versetzung hat keinen.
|
||||
{ header: "Untertyp", get: (e) => e.subtype ?? "" },
|
||||
{ header: "Vorname", get: (e) => e.first_name },
|
||||
{ header: "Nachname", get: (e) => e.last_name },
|
||||
{ header: "Position", get: (e) => e.job_title },
|
||||
{ header: "Bereich", get: (e) => (e.org_unit_id ? (lookups.divisionName.get(e.org_unit_id) ?? "") : "") },
|
||||
{ header: "Abteilung", get: (e) => (e.org_unit_id ? (lookups.departmentName.get(e.org_unit_id) ?? "") : "") },
|
||||
{ header: "Team", get: (e) => (e.org_unit_id ? (lookups.teamName.get(e.org_unit_id) ?? "") : "") },
|
||||
{ header: "Standort", get: (e) => lookups.locationName.get(e.location_id) ?? "" },
|
||||
{ header: "Beschreibung", get: (e) => e.description },
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user