diff --git a/backend/db/report.go b/backend/db/report.go index f16d1b1..3f04d4f 100644 --- a/backend/db/report.go +++ b/backend/db/report.go @@ -12,7 +12,9 @@ import ( type Report struct { ID int64 `json:"id"` UserID xid.ID `json:"user_id"` + UserName string `json:"user_name"` MemberID *xid.ID `json:"member_id"` + MemberName *string `json:"member_name"` Reason string `json:"reason"` ReporterID xid.ID `json:"reporter_id"` @@ -25,7 +27,12 @@ type Report struct { const ReportPageSize = 100 func (db *DB) Reports(ctx context.Context, closed bool, before int) (rs []Report, err error) { - builder := sq.Select("*").From("reports").Limit(ReportPageSize).OrderBy("id DESC") + builder := sq.Select("*", + "(SELECT username FROM users WHERE id = reports.user_id) AS user_name", + "(SELECT name FROM members WHERE id = reports.member_id) AS member_name"). + From("reports"). + Limit(ReportPageSize). + OrderBy("id DESC") if before != 0 { builder = builder.Where("id < ?", before) } diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index b285187..3198edb 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -84,7 +84,9 @@ export interface Invite { export interface Report { id: string; user_id: string; + user_name: string; member_id: string | null; + member_name: string | null; reason: string; reporter_id: string; diff --git a/frontend/src/routes/reports/+page.svelte b/frontend/src/routes/reports/+page.svelte index 7f17dcf..1fc086e 100644 --- a/frontend/src/routes/reports/+page.svelte +++ b/frontend/src/routes/reports/+page.svelte @@ -1,5 +1,40 @@ + + + Reports - pronouns.cc + + +
+

Reports

+ +
+ {#each data.reports as report} + + + #{report.id} on @{report.user_name} + ({report.user_id}) {#if report.member_id} + (member: {report.member_name}, + {report.member_id}) + {/if} + + +
{report.reason}
+
+ + Created {DateTime.fromISO(report.created_at) + .toLocal() + .toLocaleString(DateTime.DATETIME_MED)} • + + + + +
+ {/each} +
+
diff --git a/frontend/src/routes/reports/+page.ts b/frontend/src/routes/reports/+page.ts index 260f0d4..85ef6f4 100644 --- a/frontend/src/routes/reports/+page.ts +++ b/frontend/src/routes/reports/+page.ts @@ -1,9 +1,17 @@ -import type { Report } from "$lib/api/entities"; +import { ErrorCode, type APIError, type Report } from "$lib/api/entities"; import { apiFetchClient } from "$lib/api/fetch"; +import { error } from "@sveltejs/kit"; export const load = async () => { - const reports = await apiFetchClient("/admin/reports"); - return { page: 0, isClosed: false, userId: null, reporterId: null, reports } as PageLoadData; + try { + const reports = await apiFetchClient("/admin/reports"); + return { page: 0, isClosed: false, userId: null, reporterId: null, reports } as PageLoadData; + } catch (e) { + if ((e as APIError).code === ErrorCode.Forbidden) { + throw error(400, "You're not an admin"); + } + throw e; + } }; interface PageLoadData {