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 });
};

View File

@@ -0,0 +1,95 @@
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.listAirports(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, city, latitude, longitude, timezone } =
body as {
name?: string;
country?: string;
country_code?: string;
iata_code?: string | null;
icao_code?: string | null;
city?: string | null;
latitude?: number | null;
longitude?: number | null;
timezone?: string | null;
};
if (!name?.trim() || !country?.trim() || !country_code?.trim()) {
return json({ error: 'name, country and country_code required' }, { status: 400 });
}
return json(
data.createAirport(
name,
country,
country_code,
iata_code ?? null,
icao_code ?? null,
city ?? null,
latitude ?? null,
longitude ?? null,
timezone ?? 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,
city,
latitude,
longitude,
timezone
} = body as {
id?: number;
name?: string;
country?: string;
country_code?: string;
iata_code?: string | null;
icao_code?: string | null;
city?: string | null;
latitude?: number | null;
longitude?: number | null;
timezone?: string | null;
};
if (id == null || !name?.trim() || !country?.trim() || !country_code?.trim()) {
return json({ error: 'id, name, country and country_code required' }, { status: 400 });
}
data.updateAirport(
id,
name,
country,
country_code,
iata_code ?? null,
icao_code ?? null,
city ?? null,
latitude ?? null,
longitude ?? null,
timezone ?? 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.deleteAirport(id);
return json({ ok: true });
};

View File

@@ -0,0 +1,51 @@
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;
const countryCode = event.url.searchParams.get('country_code') ?? undefined;
return json(data.listCities(q, countryCode));
};
export const POST: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { name, country, country_code, population } = body as {
name?: string;
country?: string;
country_code?: string;
population?: number | null;
};
if (!name?.trim() || !country?.trim() || !country_code?.trim()) {
return json({ error: 'name, country and country_code required' }, { status: 400 });
}
return json(data.createCity(name, country, country_code, population ?? 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, population } = body as {
id?: number;
name?: string;
country?: string;
country_code?: string;
population?: number | null;
};
if (id == null || !name?.trim() || !country?.trim() || !country_code?.trim()) {
return json({ error: 'id, name, country and country_code required' }, { status: 400 });
}
data.updateCity(id, name, country, country_code, population ?? 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.deleteCity(id);
return json({ ok: true });
};

View File

@@ -0,0 +1,39 @@
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.listCountries(q));
};
export const POST: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { name, country_code } = body as { name?: string; country_code?: string };
if (!name?.trim() || !country_code?.trim()) {
return json({ error: 'name and country_code required' }, { status: 400 });
}
return json(data.createCountry(name, country_code));
};
export const PATCH: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { id, name, country_code } = body as { id?: number; name?: string; country_code?: string };
if (id == null || !name?.trim() || !country_code?.trim()) {
return json({ error: 'id, name and country_code required' }, { status: 400 });
}
data.updateCountry(id, name, country_code);
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.deleteCountry(id);
return json({ ok: true });
};

View File

@@ -0,0 +1,48 @@
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.listTourOperators(q));
};
export const POST: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { name, website, highlight_color } = body as {
name?: string;
website?: string | null;
highlight_color?: string | null;
};
if (!name?.trim()) {
return json({ error: 'name is required' }, { status: 400 });
}
return json(data.createTourOperator(name, website, highlight_color));
};
export const PATCH: RequestHandler = async (event) => {
requireAdmin((await event.locals.auth())?.user?.id);
const body = await event.request.json();
const { id, name, website, highlight_color } = body as {
id?: number;
name?: string;
website?: string | null;
highlight_color?: string | null;
};
if (id == null || !name?.trim()) {
return json({ error: 'id and name are required' }, { status: 400 });
}
data.updateTourOperator(id, name, website, highlight_color);
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.deleteTourOperator(id);
return json({ ok: true });
};