adds search api

This commit is contained in:
Christian Beutel
2024-03-10 00:52:45 +01:00
parent 963b589b2d
commit 01e1053569
25 changed files with 271 additions and 87 deletions

View File

@@ -0,0 +1,13 @@
import type { Category } from "$lib/models/category";
import { pb } from "$lib/pocketbase";
import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function GET(event: RequestEvent) {
try {
const r: Category[] = await pb.collection('categories').getFullList<Category>()
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}

View File

@@ -0,0 +1,23 @@
import { pb } from "$lib/pocketbase";
import { error, text, type RequestEvent } from "@sveltejs/kit";
export async function GET(event: RequestEvent) {
const parts = [];
parts.push("api");
parts.push("files");
parts.push(encodeURIComponent(event.params.collection as string));
parts.push(encodeURIComponent(event.params.record as string));
parts.push(encodeURIComponent(event.params.file as string));
let fileURL = pb.buildUrl(parts.join("/"));
try {
const r = await event.fetch(fileURL)
return new Response(r.body, {headers: r.headers});
} catch (e: any) {
console.log(e);
throw error(500, e);
}
}

View File

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

View File

@@ -10,6 +10,6 @@ export async function POST(event: RequestEvent) {
});
return json(r);
} catch (e: any) {
throw error(e.status, e)
throw error(e.httpStatus, e)
}
}

View File

@@ -2,16 +2,6 @@ import { pb } from '$lib/pocketbase';
import type { User } from '$lib/stores/user_store';
import { error, json, type RequestEvent } from '@sveltejs/kit'
export async function POST(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await pb.collection('lists').update<User>(data.id, data.user)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}
export async function PUT(event: RequestEvent) {
const data = await event.request.json()
try {
@@ -22,12 +12,3 @@ export async function PUT(event: RequestEvent) {
}
}
export async function DELETE(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await pb.collection('users').delete(data.id)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -0,0 +1,22 @@
import { pb } from '$lib/pocketbase';
import type { User } from '$lib/stores/user_store';
import { error, json, type RequestEvent } from '@sveltejs/kit'
export async function POST(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await pb.collection('users').update<User>(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('users').delete(event.params.id as string)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}