adds trail author filter

This commit is contained in:
Christian Beutel
2024-11-15 23:57:09 +01:00
parent 24ef5998c0
commit f260b63d43
27 changed files with 345 additions and 153 deletions

View File

@@ -21,8 +21,18 @@ export async function GET(event: RequestEvent) {
.getList<Trail>(parseInt(page), parseInt(perPage), { expand: expand ?? "", sort: sort ?? "", filter: filter ?? "" })
}
for (const t of r.items) {
if (!t.author || !pb.authStore.model) {
continue;
}
if(!t.expand) {
t.expand = {} as any
}
t.expand.author = await pb.collection("users_anonymous").getOne(t.author);
}
return json(r)
} catch (e: any) {
console.error(e)
throw error(e.status, e);
}
}

View File

@@ -9,14 +9,22 @@ export async function GET(event: RequestEvent) {
const r = await pb.collection('trails')
.getOne<Trail>(event.params.id as string, { expand: expand ?? "" })
if (pb.authStore.model) {
if (!r.expand) {
r.expand = {} as any
}
r.expand.author = await pb.collection("users_anonymous").getOne(r.author!);
}
// 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)
}
return json(r)
} catch (e: any) {
throw error(e.status || 500, e);
} catch (e: any) {
throw error(e.status || 500, e);
}
}

View File

@@ -11,6 +11,9 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
q: "",
category: [],
difficulty: ["easy", "moderate", "difficult"],
author: "",
public: true,
shared: true,
near: {
radius: 2000,
},

View File

@@ -10,6 +10,9 @@ export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
q: "",
category: [],
difficulty: ["easy", "moderate", "difficult"],
author: "",
public: true,
shared: true,
near: {
radius: 2000,
},