add option to create a report via the admin panel
All checks were successful
delpoy / build-and-deploy (push) Successful in 47s
All checks were successful
delpoy / build-and-deploy (push) Successful in 47s
This commit is contained in:
@@ -5,6 +5,7 @@ import { Admin, Report, User } from '$lib/server/database';
|
||||
import type { Attributes } from 'sequelize';
|
||||
import { Op } from 'sequelize';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import crypto from 'crypto';
|
||||
|
||||
export const POST = (async ({ request, cookies }) => {
|
||||
if (getSession(cookies, { permissions: [Permissions.ReportRead] }) == null) {
|
||||
@@ -104,3 +105,49 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
|
||||
return new Response();
|
||||
}) satisfies RequestHandler;
|
||||
|
||||
export const PUT = (async ({ request, cookies, url }) => {
|
||||
if (getSession(cookies, { permissions: [Permissions.ReportWrite] }) == null) {
|
||||
return new Response(null, {
|
||||
status: 401
|
||||
});
|
||||
}
|
||||
|
||||
const data: {
|
||||
reporter: string;
|
||||
reported: string;
|
||||
reason: string;
|
||||
body: string | null;
|
||||
} = await request.json();
|
||||
|
||||
if (
|
||||
data.reporter == null ||
|
||||
data.reported == 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 } });
|
||||
|
||||
if (reporter == null || reported == null) return new Response(null, { status: 400 });
|
||||
|
||||
const report = await Report.create({
|
||||
subject: data.reason,
|
||||
body: data.body,
|
||||
draft: data.body === null,
|
||||
status: 'none',
|
||||
url_hash: crypto.randomBytes(18).toString('hex'),
|
||||
completed: false,
|
||||
reporter_id: reporter.id,
|
||||
reported_id: reported.id
|
||||
});
|
||||
report.dataValues.reporter = await User.findOne({ where: { id: report.reporter_id } });
|
||||
report.dataValues.reported = await User.findOne({ where: { id: report.reported_id } });
|
||||
report.dataValues.auditor = null;
|
||||
|
||||
return new Response(JSON.stringify(report), {
|
||||
status: 201
|
||||
});
|
||||
}) satisfies RequestHandler;
|
||||
|
||||
Reference in New Issue
Block a user