Files
alpenwerk-hr/app/api/cron/apply-pending-changes/route.ts
Maximilian Stubhan f96773da0f Reports/Export builder (CSV/XLSX), plus a security fix pass
Adds the Berichte export pipeline (/api/export/{report,events,employees})
with shared CSV/XLSX writers in lib/export.ts and lib/reports-data.ts.

Security pass alongside it: sanitize .or() search terms against PostgREST
filter injection, sanitize spreadsheet cells against CSV/Excel formula
injection, stop leaking raw DB error messages to clients, harden the
service-role client with server-only, add baseline security headers, and
bump the vulnerable nested postcss via an override.
2026-07-15 20:34:27 +02:00

26 lines
1.2 KiB
TypeScript

import { NextResponse, type NextRequest } from "next/server";
import { createAdminClient } from "@/lib/supabase/admin";
// Applies effective-dated changes (Versetzung/Beförderung/Karenz/Reorg/Daten
// ändern with a future "Wirksam ab" date) once their date has arrived — see
// apply_due_pending_changes() in supabase/migrations. Runs as a Vercel Cron
// job (see vercel.json), not on behalf of any HR user, so it authenticates
// via a shared secret rather than a Supabase session and uses the
// service-role client (the one legitimate server-only use case for it).
export async function GET(request: NextRequest) {
const authHeader = request.headers.get("authorization");
if (!process.env.CRON_SECRET || authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return NextResponse.json({ error: "Nicht autorisiert." }, { status: 401 });
}
const supabase = createAdminClient();
const { data, error } = await supabase.rpc("apply_due_pending_changes");
if (error) {
console.error("apply_due_pending_changes failed:", error);
return NextResponse.json({ error: "Interner Fehler." }, { status: 500 });
}
return NextResponse.json({ applied: data });
}