2026-04-17 15:12:59 +02:00
|
|
|
import type { RequestHandler } from './$types';
|
2026-04-18 22:19:12 +02:00
|
|
|
import { json } from '@sveltejs/kit';
|
2026-04-17 15:12:59 +02:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
import { getDb } from '$lib/server/db';
|
2026-04-18 22:19:12 +02:00
|
|
|
import { parsePositiveIntParam, validateBody } from '$lib/server/api-helpers';
|
2026-04-17 15:12:59 +02:00
|
|
|
import { deleteProfile, renameProfile } from '$lib/server/profiles/repository';
|
|
|
|
|
|
|
|
|
|
const RenameSchema = z.object({ name: z.string().min(1).max(50) });
|
|
|
|
|
|
|
|
|
|
export const PATCH: RequestHandler = async ({ params, request }) => {
|
2026-04-18 22:19:12 +02:00
|
|
|
const id = parsePositiveIntParam(params.id, 'id');
|
|
|
|
|
const data = validateBody(await request.json().catch(() => null), RenameSchema);
|
|
|
|
|
renameProfile(getDb(), id, data.name);
|
2026-04-17 15:12:59 +02:00
|
|
|
return json({ ok: true });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const DELETE: RequestHandler = async ({ params }) => {
|
2026-04-18 22:19:12 +02:00
|
|
|
const id = parsePositiveIntParam(params.id, 'id');
|
2026-04-17 15:12:59 +02:00
|
|
|
deleteProfile(getDb(), id);
|
|
|
|
|
return json({ ok: true });
|
|
|
|
|
};
|