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(