From 2e713273ca7a2e6496fa834c0a15175670fc0686 Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 10 Jun 2025 00:03:38 +0200 Subject: [PATCH] update reports --- README.md | 69 ++++++++++++++++++ src/actions/report.ts | 13 +++- src/app/admin/reports/BottomBar.svelte | 7 +- src/app/admin/reports/reports.ts | 4 +- src/db/database.sql | 37 +++++----- src/db/database.ts | 11 ++- src/db/schema/report.ts | 15 ++-- src/db/schema/reportStatus.ts | 8 +-- src/db/schema/strike.ts | 35 ++++++++-- src/db/schema/team.ts | 4 +- src/pages/api/report/index.ts | 96 ++++++++++++++++++++++++++ 11 files changed, 249 insertions(+), 50 deletions(-) create mode 100644 src/pages/api/report/index.ts diff --git a/README.md b/README.md index 20e3226..eba2a4d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,75 @@ +
+POST /api/report (Erstellt einen Report) + +##### Request Body + +``` +{ + // UUID des Report Erstellers + "reporter": string, + // UUID des Reporteten Spielers + "reported": string | null, + // Report Grund + "reason": string +} +``` + +##### Response Codes + +| http code | beschreibung | +| --------- | ----------------------------------------------------------------- | +| 200 | / | +| 400 | Der Request Body ist falsch | +| 401 | Es wurde ein falsches API Secret angegeben | +| 404 | Der Report Ersteller, oder der reportete Spieler, existiert nicht | + +##### Response Body + +``` +{ + // URL, wo der Ersteller den Report abschicken kann + "url": string +} +``` + +
+ +
+PUT /api/report (Erstellt einen Abgeschlossenen Report) + +##### Request Body + +``` +{ + // UUID des Reporters. Wenn `null`, wird der Reporter als System interpretiert + "reporter": string | null, + // UUID des Reporteten Spielers + "reported": string, + // Report Grund + "reason": string, + // Inhalt des Reports + "body": string | null, + // Interne Notiz + "notice": string | null, + // Öffentliches Statement + "statement": string | null, + // ID des Strikegrundes + "strike_reason_id": number +} +``` + +| http code | beschreibung | +| --------- | ----------------------------------------------------------------- | +| 200 | / | +| 400 | Der Request Body ist falsch | +| 401 | Es wurde ein falsches API Secret angegeben | +| 404 | Der Report Ersteller, oder der reportete Spieler, existiert nicht | + +
+
POST /api/player/death (Registriert einen Spielertod) diff --git a/src/actions/report.ts b/src/actions/report.ts index d3d3a0a..9f47f87 100644 --- a/src/actions/report.ts +++ b/src/actions/report.ts @@ -47,12 +47,21 @@ export const report = { status: z.enum(['open', 'closed']).nullable(), notice: z.string().nullable(), statement: z.string().nullable(), - strikeId: z.number().nullable() + strikeReasonId: z.number().nullable() }), handler: async (input, context) => { Session.actionSessionFromCookies(context.cookies, Permissions.Reports); - await db.editReportStatus(input); + await db.transaction(async (tx) => { + await tx.editReportStatus(input); + + if (input.strikeReasonId) { + await db.editStrike({ + reportId: input.reportId, + strikeReasonId: input.strikeReasonId + }); + } + }); } }), reports: defineAction({ diff --git a/src/app/admin/reports/BottomBar.svelte b/src/app/admin/reports/BottomBar.svelte index 5d2cfee..95ccd5e 100644 --- a/src/app/admin/reports/BottomBar.svelte +++ b/src/app/admin/reports/BottomBar.svelte @@ -20,6 +20,7 @@ let status = $state<'open' | 'closed' | null>(null); let notice = $state(null); let statement = $state(null); + let strikeReason = $state(null); // consts const strikeReasonValues = strikeReasons.reduce( @@ -50,7 +51,7 @@ status: status, notice: notice, statement: statement, - strikeId: null + strikeReasonId: Number(strikeReason) } as ReportStatus) }; } @@ -75,12 +76,14 @@