trail save fix

This commit is contained in:
Christian Beutel
2025-02-14 13:22:20 +01:00
parent a2ad4a4800
commit bd8bae2ac9
43 changed files with 164 additions and 105 deletions

View File

@@ -0,0 +1,14 @@
import { pb } from "$lib/pocketbase";
import { handleError } from "$lib/util/api_util";
import { json } from "@sveltejs/kit";
export async function GET() {
try {
const r = await pb.send("/integration/komoot/login", {
method: "GET",
});
return json(r);
} catch (e: any) {
throw handleError(e)
}
}

View File

@@ -7,7 +7,7 @@ export async function POST(event: RequestEvent) {
const r = await event.locals.ms.index(event.params.index as string).search(data.q, data.options);
return json(r);
} catch (e: any) {
console.log(e);
console.error(e);
throw error(e.httpStatus, e)
}

View File

@@ -16,17 +16,7 @@ export async function GET(event: RequestEvent) {
}
// remove time from dates
r.date = r.date?.substring(0, 10) ?? ""
for (const log of r.expand?.summit_logs ?? []) {
log.date = log.date.substring(0, 10)
if (!log.expand) {
log.expand = {} as any
}
if (log.author) {
log.expand!.author = await pb.collection("users_anonymous").getOne(log.author);
}
}
await enrichRecord(r);
// sort waypoints by distance
r.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
@@ -36,10 +26,10 @@ export async function GET(event: RequestEvent) {
}
}
export async function POST(event: RequestEvent) {
try {
const r = await update<Trail>(event, TrailUpdateSchema, Collection.trails)
await enrichRecord(r)
return json(r);
} catch (e: any) {
throw handleError(e)
@@ -54,3 +44,19 @@ export async function DELETE(event: RequestEvent) {
throw handleError(e)
}
}
async function enrichRecord(r: Trail) {
r.date = r.date?.substring(0, 10) ?? "";
for (const log of r.expand?.summit_logs ?? []) {
log.date = log.date.substring(0, 10);
if (!log.expand) {
log.expand = {} as any;
}
if (log.author) {
log.expand!.author = await pb.collection("users_anonymous").getOne(log.author);
}
}
}

View File

@@ -50,7 +50,7 @@ export async function PUT(event: RequestEvent) {
const fileName = (data.get("name") as string | null)?.length ? data.get("name") as string : "file"
log._gpx = new File([gpxFile], fileName);
trail.expand!.summit_logs.push(log);
trail.expand!.summit_logs?.push(log);
try {