CI / Architecture Guardrails (push) Successful in 2m38s
CI / Assistant Split Regression (push) Successful in 3m33s
CI / Typecheck (push) Successful in 3m51s
CI / Lint (push) Successful in 5m2s
CI / E2E Tests (push) Has been cancelled
CI / Fresh-Linux Docker Deploy (push) Has been cancelled
CI / Release Images (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
rename(phase 1): CapaKraken → Nexus across code, UI, docs, CI (#61) Co-authored-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com> Co-committed-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "@nexus/db";
|
|
import { autoImportPublicHolidays } from "@nexus/api";
|
|
import { logger } from "@nexus/api/lib/logger";
|
|
import { verifyCronSecret } from "~/lib/cron-auth.js";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
export const runtime = "nodejs";
|
|
|
|
/**
|
|
* GET /api/cron/public-holidays?year=2027
|
|
*
|
|
* Auto-imports public holidays for all active resources for a given year.
|
|
* Each resource's federal state determines which state-specific holidays apply.
|
|
* Duplicate-safe: existing holidays are skipped.
|
|
*
|
|
* Query params:
|
|
* - year (optional): defaults to next year
|
|
*
|
|
* Protected with CRON_SECRET via `Authorization: Bearer <secret>` header.
|
|
*/
|
|
export async function GET(request: Request) {
|
|
const deny = verifyCronSecret(request);
|
|
if (deny) return deny;
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const yearParam = searchParams.get("year");
|
|
const year = yearParam ? parseInt(yearParam, 10) : new Date().getFullYear() + 1;
|
|
|
|
if (isNaN(year) || year < 2000 || year > 2100) {
|
|
return NextResponse.json(
|
|
{ error: "Invalid year parameter. Must be between 2000 and 2100." },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const result = await autoImportPublicHolidays(prisma, year);
|
|
|
|
return NextResponse.json({
|
|
ok: true,
|
|
year: result.year,
|
|
holidaysCreated: result.holidaysCreated,
|
|
resourcesProcessed: result.resourcesProcessed,
|
|
skippedExisting: result.skippedExisting,
|
|
});
|
|
} catch (error) {
|
|
logger.error(
|
|
{ error, route: "/api/cron/public-holidays", year },
|
|
"Public holiday import cron failed",
|
|
);
|
|
return NextResponse.json({ ok: false, error: "Internal error" }, { status: 500 });
|
|
}
|
|
}
|