make reported user nullable
All checks were successful
delpoy / build-and-deploy (push) Successful in 44s

This commit is contained in:
2023-11-03 18:10:02 +01:00
parent 72eeb59230
commit 81d97380ca
11 changed files with 107 additions and 65 deletions

View File

@ -8,15 +8,14 @@ export const POST = (async ({ request, url }) => {
if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET)
return new Response(null, { status: 401 });
const data: { reporter: string; reported: string; reason: string } = await request.json();
const data: { reporter: string; reported: string | null; reason: string } = await request.json();
if (data.reporter == null || data.reported == null || data.reason == null)
return new Response(null, { status: 400 });
if (data.reporter == null || data.reason == null) return new Response(null, { status: 400 });
const reporter = await User.findOne({ where: { uuid: data.reporter } });
const reported = await User.findOne({ where: { uuid: data.reported } });
const reported = data.reported ? await User.findOne({ where: { uuid: data.reported } }) : null;
if (reporter == null || reported == null) return new Response(null, { status: 400 });
if (reporter == null) return new Response(null, { status: 400 });
const report = await Report.create({
subject: data.reason,
@ -26,7 +25,7 @@ export const POST = (async ({ request, url }) => {
url_hash: crypto.randomBytes(18).toString('hex'),
completed: false,
reporter_id: reporter.id,
reported_id: reported.id
reported_id: reported?.id || null
});
return new Response(

View File

@ -22,7 +22,7 @@ export const load: PageServerLoad = async ({ params }) => {
name: report.reporter.username
},
reported: {
name: report.reported.username
name: report.reported?.username || null
}
};
};

View File

@ -18,6 +18,7 @@
<div class="col-[1] row-[1]" transition:fly={{ x: -200, duration: 300 }}>
<ReportDraft
reason={data.reason}
reporterName={data.reporter.name}
reportedName={data.reported.name}
on:submit={() => (data.draft = false)}
/>

View File

@ -5,7 +5,8 @@
import { page } from '$app/stores';
import { createEventDispatcher } from 'svelte';
export let reportedName: string;
export let reporterName: string;
export let reportedName: string | null;
export let reason: string;
let body: string;
@ -25,7 +26,10 @@
</script>
<div>
<h2 class="text-3xl text-center">Report für <code>{reportedName}</code></h2>
<h2 class="text-3xl text-center">
Report von <span class="underline">{reporterName}</span> gegen
<span class="underline">{reportedName || 'unbekannt'}</span>
</h2>
<form on:submit|preventDefault={() => submitModal.show()}>
<div class="space-y-4 my-4">
<div>