package-tours) adding support for pre-defining tours
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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 tourId = parseInt(event.url.searchParams.get('operator_tour_id') ?? '');
|
||||
if (isNaN(tourId)) return json({ error: 'operator_tour_id required' }, { status: 400 });
|
||||
return json(data.listDaysForOperatorTour(tourId));
|
||||
};
|
||||
|
||||
export const POST: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
const body = await event.request.json();
|
||||
const { operator_tour_id, title, notes } = body as {
|
||||
operator_tour_id?: number;
|
||||
title?: string;
|
||||
notes?: string;
|
||||
};
|
||||
if (operator_tour_id == null) {
|
||||
return json({ error: 'operator_tour_id is required' }, { status: 400 });
|
||||
}
|
||||
return json(data.createOperatorTourDay(operator_tour_id, title, notes));
|
||||
};
|
||||
|
||||
export const PATCH: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
const body = await event.request.json();
|
||||
const { id, title, notes } = body as { id?: number; title?: string; notes?: string };
|
||||
if (id == null) return json({ error: 'id is required' }, { status: 400 });
|
||||
data.updateOperatorTourDay(id, title, notes);
|
||||
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.deleteOperatorTourDay(id);
|
||||
return json({ ok: true });
|
||||
};
|
||||
40
src/routes/(protected)/admin/api/operator-tours/+server.ts
Normal file
40
src/routes/(protected)/admin/api/operator-tours/+server.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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 operatorId = parseInt(event.url.searchParams.get('operator_id') ?? '');
|
||||
if (isNaN(operatorId)) return json({ error: 'operator_id required' }, { status: 400 });
|
||||
return json(data.listToursForOperator(operatorId));
|
||||
};
|
||||
|
||||
export const POST: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
const body = await event.request.json();
|
||||
const { operator_id, name } = body as { operator_id?: number; name?: string };
|
||||
if (operator_id == null || !name?.trim()) {
|
||||
return json({ error: 'operator_id and name are required' }, { status: 400 });
|
||||
}
|
||||
return json(data.createOperatorTour(operator_id, name));
|
||||
};
|
||||
|
||||
export const PATCH: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
const body = await event.request.json();
|
||||
const { id, name } = body as { id?: number; name?: string };
|
||||
if (id == null || !name?.trim()) {
|
||||
return json({ error: 'id and name are required' }, { status: 400 });
|
||||
}
|
||||
data.updateOperatorTour(id, name);
|
||||
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.deleteOperatorTour(id);
|
||||
return json({ ok: true });
|
||||
};
|
||||
23
src/routes/(protected)/admin/api/provider-search/+server.ts
Normal file
23
src/routes/(protected)/admin/api/provider-search/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { requireAdmin } from '$lib/server/admin/auth.js';
|
||||
import { listTourOperators } from '$lib/server/admin/data.js';
|
||||
import { getProviderForOperator } from '$lib/server/admin/providers/index.js';
|
||||
|
||||
export const GET: RequestHandler = async (event) => {
|
||||
requireAdmin((await event.locals.auth())?.user?.id);
|
||||
|
||||
const operatorId = parseInt(event.url.searchParams.get('operator_id') ?? '');
|
||||
if (isNaN(operatorId)) return json({ error: 'operator_id required' }, { status: 400 });
|
||||
|
||||
const operators = listTourOperators();
|
||||
const operator = operators.find((o) => o.id === operatorId);
|
||||
if (!operator) return json({ error: 'Operator not found' }, { status: 404 });
|
||||
|
||||
const provider = getProviderForOperator(operator.name);
|
||||
if (!provider) return json({ error: 'No provider for this operator' }, { status: 404 });
|
||||
|
||||
const q = event.url.searchParams.get('q') ?? '';
|
||||
const results = await provider.search(q);
|
||||
return json(results);
|
||||
};
|
||||
Reference in New Issue
Block a user