import type { RequestHandler } from '@sveltejs/kit';
import { Report } from '$lib/server/database';

export const POST = (async ({ request, params }) => {
	const report = await Report.findOne({ where: { url_hash: params.url_hash } });

	if (report == null) return new Response(null, { status: 400 });

	const data: { body: string } = await request.json();

	report.draft = false;
	report.body = data.body || '';
	await report.save();

	return new Response(null, { status: 200 });
}) satisfies RequestHandler;
