Files
kochwas/src/routes/api/profiles/[id]/+server.ts

22 lines
837 B
TypeScript
Raw Normal View History

import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import { z } from 'zod';
import { getDb } from '$lib/server/db';
import { parsePositiveIntParam, validateBody } from '$lib/server/api-helpers';
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 }) => {
const id = parsePositiveIntParam(params.id, 'id');
const data = validateBody(await request.json().catch(() => null), RenameSchema);
renameProfile(getDb(), id, data.name);
return json({ ok: true });
};
export const DELETE: RequestHandler = async ({ params }) => {
const id = parsePositiveIntParam(params.id, 'id');
deleteProfile(getDb(), id);
return json({ ok: true });
};