make reported user nullable
All checks were successful
delpoy / build-and-deploy (push) Successful in 44s
All checks were successful
delpoy / build-and-deploy (push) Successful in 44s
This commit is contained in:
@@ -92,6 +92,7 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
|
||||
const data: {
|
||||
id: number;
|
||||
reported: string | null;
|
||||
auditor: number;
|
||||
notice: string | null;
|
||||
statement: string | null;
|
||||
@@ -102,9 +103,13 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
|
||||
const report = await Report.findOne({ where: { id: data.id } });
|
||||
const admin = await Admin.findOne({ where: { id: data.auditor } });
|
||||
if (report === null || (admin === null && data.auditor != -1))
|
||||
const reported = data.reported
|
||||
? await User.findOne({ where: { uuid: data.reported } })
|
||||
: undefined;
|
||||
if (report === null || (admin === null && data.auditor != -1) || reported === null)
|
||||
return new Response(null, { status: 400 });
|
||||
|
||||
report.reported_id = reported?.id || null;
|
||||
if (data.notice != null) report.notice = data.notice;
|
||||
if (data.statement != null) report.statement = data.statement;
|
||||
if (data.status != null) report.status = data.status;
|
||||
@@ -115,7 +120,7 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
return new Response();
|
||||
}) satisfies RequestHandler;
|
||||
|
||||
export const PUT = (async ({ request, cookies, url }) => {
|
||||
export const PUT = (async ({ request, cookies }) => {
|
||||
if (getSession(cookies, { permissions: [Permissions.ReportWrite] }) == null) {
|
||||
return new Response(null, {
|
||||
status: 401
|
||||
@@ -124,23 +129,18 @@ export const PUT = (async ({ request, cookies, url }) => {
|
||||
|
||||
const data: {
|
||||
reporter: string;
|
||||
reported: string;
|
||||
reported: string | null;
|
||||
reason: string;
|
||||
body: string | null;
|
||||
} = await request.json();
|
||||
|
||||
if (
|
||||
data.reporter == null ||
|
||||
data.reported == null ||
|
||||
data.reason == null ||
|
||||
data.body === undefined
|
||||
)
|
||||
if (data.reporter == null || data.reason == null || data.body === undefined)
|
||||
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,
|
||||
@@ -150,10 +150,12 @@ export const PUT = (async ({ request, cookies, url }) => {
|
||||
url_hash: crypto.randomBytes(18).toString('hex'),
|
||||
completed: false,
|
||||
reporter_id: reporter.id,
|
||||
reported_id: reported.id
|
||||
reported_id: reported?.id || null
|
||||
});
|
||||
report.dataValues.reporter = await User.findOne({ where: { id: report.reporter_id } });
|
||||
report.dataValues.reported = await User.findOne({ where: { id: report.reported_id } });
|
||||
report.dataValues.reported = report.reported_id
|
||||
? await User.findOne({ where: { id: report.reported_id } })
|
||||
: null;
|
||||
report.dataValues.auditor = null;
|
||||
|
||||
return new Response(JSON.stringify(report), {
|
||||
|
||||
Reference in New Issue
Block a user