/** * Synchronises the public-holiday cache from the command line. * * npm run holidays:sync * * The nightly job does this on its own; this exists for the first run after a * deployment, and for checking the API is reachable from a new host without * having to wait until three in the morning to find out. */ import 'dotenv/config'; import { prisma } from '../lib/db'; import { syncHolidays } from '../lib/holidays/sync'; async function main(): Promise { const result = await syncHolidays(); if (!result.ok) { console.error(`Échec : ${result.error}`); console.error('Le cache local est intact.'); process.exitCode = 1; return; } console.log( `Fenêtre ${result.from} → ${result.to} : ` + `${result.created} ajouté(s), ${result.updated} corrigé(s), ${result.removed} retiré(s).`, ); const upcoming = await prisma.publicHoliday.findMany({ orderBy: { date: 'asc' }, take: 6 }); for (const row of upcoming) { console.log( ` ${row.date.toISOString().slice(0, 10)} ${row.nameFr.padEnd(24)} ${row.nameEn.padEnd(24)} ` + `${row.isAutoClosed ? 'fermé' : 'ouvert'}`, ); } } main() .catch((error: unknown) => { console.error(error); process.exitCode = 1; }) .finally(() => { void prisma.$disconnect(); });