trips) adding package-tours option
This commit is contained in:
63
src/routes/(protected)/admin/api/airlines/+server.ts
Normal file
63
src/routes/(protected)/admin/api/airlines/+server.ts
Normal 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 });
|
||||
};
|
||||
Reference in New Issue
Block a user