Fix reports endpoint and added user api endpoint

This commit is contained in:
2026-07-14 15:57:10 +02:00
parent 756a9e7ec3
commit 0299bbe882
2 changed files with 60 additions and 1 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ export async function POST(req: Request) {
const { discordId, username, category, description, evidenceUrl } = parsed.data; const { discordId, username, category, description, evidenceUrl } = parsed.data;
const report = await prisma.$transaction(async (tx) => { const report = await prisma.$transaction(async (tx: any) => {
await tx.reportedUser.upsert({ await tx.reportedUser.upsert({
where: { discordId }, where: { discordId },
create: { discordId, username }, create: { discordId, username },
+59
View File
@@ -0,0 +1,59 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { authenticateRequest } from "@/lib/auth";
import { checkRateLimit } from "@/lib/rateLimit";
/**
* GET /api/v1/users/:discordId
* Geeft alleen APPROVED reports terug — pending/rejected reports zijn nooit
* publiek zichtbaar via deze endpoint, ook niet voor SUBMITTER keys.
*/
export async function GET(
req: Request,
{ params }: { params: { discordId: string } }
) {
const auth = await authenticateRequest(req);
if (!auth.ok) return NextResponse.json({ error: auth.error }, { status: auth.status });
const rate = await checkRateLimit(auth.apiKey);
if (!rate.allowed) {
return NextResponse.json(
{ error: "Rate limit overschreden" },
{ status: 429, headers: { "Retry-After": String(Math.ceil((rate.retryAfterMs ?? 0) / 1000)) } }
);
}
const { discordId } = params;
if (!/^\d{17,20}$/.test(discordId)) {
return NextResponse.json({ error: "Ongeldig Discord user ID" }, { status: 400 });
}
const user = await prisma.reportedUser.findUnique({
where: { discordId },
include: {
reports: {
where: { status: "APPROVED" },
orderBy: { createdAt: "desc" },
select: {
id: true,
category: true,
description: true,
evidenceUrl: true,
createdAt: true,
},
},
},
});
if (!user || user.reports.length === 0) {
return NextResponse.json({ discordId, found: false, reports: [] });
}
return NextResponse.json({
discordId,
found: true,
username: user.username,
reportCount: user.reports.length,
reports: user.reports,
});
}