adds search api
This commit is contained in:
13
web/src/routes/api/v1/category/+server.ts
Normal file
13
web/src/routes/api/v1/category/+server.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
22
web/src/routes/api/v1/user/[id]/+server.ts
Normal file
22
web/src/routes/api/v1/user/[id]/+server.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user