19 lines
651 B
TypeScript
19 lines
651 B
TypeScript
|
|
import { json } from '@sveltejs/kit';
|
||
|
|
import { getRandomLieu, sanitizeRound } from '$lib/server/lieux';
|
||
|
|
import type { RequestHandler } from './$types';
|
||
|
|
|
||
|
|
/** GET /api/round?region=&categorie=&exclude=id1,id2 → lieu aléatoire SANITISÉ. */
|
||
|
|
export const GET: RequestHandler = ({ url }) => {
|
||
|
|
const lieu = getRandomLieu({
|
||
|
|
region: url.searchParams.get('region'),
|
||
|
|
categorie: url.searchParams.get('categorie'),
|
||
|
|
exclude: url.searchParams.get('exclude')
|
||
|
|
});
|
||
|
|
if (!lieu) {
|
||
|
|
return json({ erreur: 'Aucun lieu disponible pour ces critères' }, { status: 404 });
|
||
|
|
}
|
||
|
|
return json(sanitizeRound(lieu), {
|
||
|
|
headers: { 'Cache-Control': 'no-store' }
|
||
|
|
});
|
||
|
|
};
|