trips) adding package-tours option

This commit is contained in:
2026-02-19 13:08:25 -05:00
parent 50e216daec
commit dba9aa0416
51 changed files with 5581 additions and 57 deletions

View File

@@ -0,0 +1,63 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { requireAdmin } from '$lib/server/admin/auth.js';
import * as data from '$lib/server/admin/data.js';
export const GET: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const q = event.url.searchParams.get('q') ?? undefined;
return json(data.listAirlines(q));
};
export const POST: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { name, country, country_code, iata_code, icao_code } = body as {
name?: string;
country?: string | null;
country_code?: string | null;
iata_code?: string | null;
icao_code?: string | null;
};
if (!name?.trim()) return json({ error: 'name required' }, { status: 400 });
return json(
data.createAirline(
name,
country ?? null,
country_code ?? null,
iata_code ?? null,
icao_code ?? null
)
);
};
export const PATCH: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { id, name, country, country_code, iata_code, icao_code } = body as {
id?: number;
name?: string;
country?: string | null;
country_code?: string | null;
iata_code?: string | null;
icao_code?: string | null;
};
if (id == null || !name?.trim()) return json({ error: 'id and name required' }, { status: 400 });
data.updateAirline(
id,
name,
country ?? null,
country_code ?? null,
iata_code ?? null,
icao_code ?? null
);
return json({ ok: true });
};
export const DELETE: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const id = parseInt(event.url.searchParams.get('id') ?? '');
if (isNaN(id)) return json({ error: 'id required' }, { status: 400 });
data.deleteAirline(id);
return json({ ok: true });
};