The rolling twelve-month window is fetched from openholidaysapi.org each night at 03:00 local, and can be triggered from the page, from POST /api/admin/holidays/sync, or from `npm run holidays:sync` for the first run after a deployment. The calendar is fetched twice, once per language, and the two answers joined on the entry id. Holiday names are proper nouns with established English forms — "Jeûne genevois" is not something a translation model should be improvising, and this costs one extra HTTP call. Two properties are load-bearing and tested against a real database. The sync is idempotent: running it twice leaves exactly what running it once did, verified live as well as against a mock. And it never touches `isAutoClosed` on an existing row — that is the shop's decision, not the API's, and a nightly job quietly reopening a day the owner had closed would be invisible until someone found the door locked. When the API is down the local cache is left untouched and the failure is recorded with its timestamp, so the page can say how stale the calendar is rather than showing nothing. Retries widen the gap between attempts; the nightly job can afford to wait, the shop cannot afford a stale calendar for a day. node-cron runs inside the application process rather than an external cron hitting an endpoint: one container, one shop, no second instance to coordinate with, and no trigger endpoint to protect and document. The reasoning is recorded next to the schedule. Verified against the live API: nine Geneva holidays, both languages, including the cantonal Restauration de la République. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { auth } from '@/lib/auth';
|
||
import { prisma } from '@/lib/db';
|
||
import { SYNC_KEY } from '@/lib/holidays/sync';
|
||
import { toCivilDate } from '@/lib/schedule/civil';
|
||
import { loadSettings } from '@/lib/schedule/context';
|
||
import { formatDateFr } from '@/lib/schedule/format';
|
||
|
||
import HolidayManager, { type HolidayRow } from './HolidayManager';
|
||
|
||
export const metadata = { title: 'Jours fériés — ITA ITO' };
|
||
|
||
export default async function HolidaysPage() {
|
||
const [session, settings] = await Promise.all([auth(), loadSettings()]);
|
||
const today = toCivilDate(new Date(), settings.timezone);
|
||
|
||
const [rows, state] = await Promise.all([
|
||
prisma.publicHoliday.findMany({
|
||
where: {
|
||
subdivisionCode: settings.subdivisionCode,
|
||
date: { gte: new Date(`${today}T00:00:00.000Z`) },
|
||
},
|
||
orderBy: { date: 'asc' },
|
||
}),
|
||
prisma.syncState.findUnique({ where: { key: SYNC_KEY } }),
|
||
]);
|
||
|
||
const holidays: HolidayRow[] = rows.map((row) => {
|
||
const date = row.date.toISOString().slice(0, 10);
|
||
return {
|
||
id: row.id,
|
||
date,
|
||
label: formatDateFr(date),
|
||
nameFr: row.nameFr,
|
||
nameEn: row.nameEn,
|
||
nationwide: row.nationwide,
|
||
isAutoClosed: row.isAutoClosed,
|
||
};
|
||
});
|
||
|
||
return (
|
||
<main className="mx-auto max-w-3xl px-4 py-10">
|
||
<h1 className="text-2xl">Jours fériés</h1>
|
||
<p className="mt-2 max-w-prose text-[var(--ink-muted)]">
|
||
Calendrier glissant sur douze mois, synchronisé chaque nuit depuis openholidaysapi.org. Tous
|
||
les fériés ne ferment pas la boutique : la case décide, pas l’API.
|
||
</p>
|
||
|
||
<HolidayManager
|
||
canEdit={session?.user?.role === 'admin'}
|
||
holidays={holidays}
|
||
subdivisionCode={settings.subdivisionCode}
|
||
lastSuccessAt={state?.lastSuccessAt ? state.lastSuccessAt.toLocaleString('fr-CH') : null}
|
||
lastError={state?.lastErrorAt ? (state.lastError ?? 'raison inconnue') : null}
|
||
/>
|
||
</main>
|
||
);
|
||
}
|