adds settings collection
This commit is contained in:
14
web/src/routes/api/v1/settings/+server.ts
Normal file
14
web/src/routes/api/v1/settings/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { Settings } from '$lib/models/settings';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function PUT(event: RequestEvent) {
|
||||
const data = await event.request.json();
|
||||
|
||||
try {
|
||||
const r = await pb.collection('settings').create<Settings>(data)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
32
web/src/routes/api/v1/settings/[id]/+server.ts
Normal file
32
web/src/routes/api/v1/settings/[id]/+server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { Settings } from "$lib/models/settings";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
try {
|
||||
const r = await pb.collection('settings').getFirstListItem<Settings>(`user="${event.params.id}"`)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await await pb.collection("settings").update<Settings>(event.params.id as string, data);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent) {
|
||||
try {
|
||||
const r = await pb.collection('settings').delete(event.params.id as string)
|
||||
return json({ 'acknowledged': r });
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
20
web/src/routes/api/v1/trail/bounding-box/+server.ts
Normal file
20
web/src/routes/api/v1/trail/bounding-box/+server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { type TrailBoundingBox, type TrailFilterValues } from '$lib/models/trail';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
if (!pb.authStore.model) {
|
||||
return json({
|
||||
max_lat: 0,
|
||||
min_lat: 0,
|
||||
max_lon: 0,
|
||||
min_lon: 0
|
||||
});
|
||||
}
|
||||
try {
|
||||
const r = await pb.collection('trails_bounding_box').getOne<TrailBoundingBox>(pb.authStore.model!.id)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status || 500, e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user