optimize post migration

This commit is contained in:
JCEEE
2026-08-17 07:41:58 +01:00
parent 5204e7bdbc
commit fb18593ac5
17 changed files with 121 additions and 132 deletions
@@ -1,14 +1,16 @@
import { json } from '@sveltejs/kit';
import { json, error } from '@sveltejs/kit';
import type { RequestEvent } from '@sveltejs/kit';
import { actingClient } from '$lib/server/routeAuth';
import { createPbClient } from '$lib/server/pocketbase';
import { createServices } from '$lib/server/services';
export async function POST(event: RequestEvent) {
const { pb, famId, userId, role } = actingClient(event);
const u = event.locals.user;
if (!u || !event.locals.pbToken) throw error(401, 'Unauthorized');
const pb = createPbClient(event.locals.pbToken);
const body = await event.request.json().catch(() => ({}));
try {
const s = createServices(pb, { id: userId, role });
return json(await s.completions.toggle(famId, body));
const s = createServices(pb, { id: u.id, role: u.role });
return json(await s.completions.toggle(u.famId, body));
} catch (e) {
return json({ error: e instanceof Error ? e.message : 'toggle failed' }, { status: 400 });
}