2026-04-10 19:24:12 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { auth } from "../../../auth";
|
|
|
|
|
import { prisma } from "../../../lib/prisma";
|
|
|
|
|
|
2026-04-10 23:09:36 +02:00
|
|
|
export async function GET() {
|
|
|
|
|
const session = await auth();
|
|
|
|
|
if (!session?.user?.id) {
|
|
|
|
|
return NextResponse.json({ error: "Non connecté" }, { status: 401 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const user = await prisma.user.findUnique({
|
|
|
|
|
where: { id: session.user.id },
|
|
|
|
|
select: { id: true, name: true, email: true, createdAt: true },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const games = await prisma.game.findMany({
|
|
|
|
|
where: { userId: session.user.id },
|
|
|
|
|
select: {
|
2026-04-11 15:20:29 +02:00
|
|
|
id: true,
|
|
|
|
|
mode: true,
|
|
|
|
|
startArticle: true,
|
|
|
|
|
targetArticle: true,
|
|
|
|
|
path: true,
|
|
|
|
|
clicks: true,
|
|
|
|
|
timeSeconds: true,
|
|
|
|
|
won: true,
|
|
|
|
|
playedAt: true,
|
2026-04-10 23:09:36 +02:00
|
|
|
},
|
|
|
|
|
orderBy: { playedAt: "desc" },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const dailyResults = await prisma.dailyResult.findMany({
|
|
|
|
|
where: { userId: session.user.id },
|
|
|
|
|
select: {
|
2026-04-11 15:20:29 +02:00
|
|
|
id: true,
|
|
|
|
|
puzzleId: true,
|
|
|
|
|
path: true,
|
|
|
|
|
clicks: true,
|
|
|
|
|
timeSeconds: true,
|
|
|
|
|
won: true,
|
|
|
|
|
playedAt: true,
|
2026-04-10 23:09:36 +02:00
|
|
|
},
|
|
|
|
|
orderBy: { playedAt: "desc" },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
profile: user,
|
|
|
|
|
games: games.map((g) => ({ ...g, path: JSON.parse(g.path) as string[] })),
|
2026-04-11 15:20:29 +02:00
|
|
|
dailyResults: dailyResults.map((d) => ({
|
|
|
|
|
...d,
|
|
|
|
|
path: JSON.parse(d.path) as string[],
|
|
|
|
|
})),
|
2026-04-10 23:09:36 +02:00
|
|
|
exportedAt: new Date().toISOString(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new NextResponse(JSON.stringify(data, null, 2), {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Content-Disposition": `attachment; filename="wikirush-data-${session.user.id}.json"`,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 19:24:12 +02:00
|
|
|
export async function DELETE() {
|
|
|
|
|
const session = await auth();
|
|
|
|
|
if (!session?.user?.id) {
|
|
|
|
|
return NextResponse.json({ error: "Non connecté" }, { status: 401 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await prisma.user.delete({ where: { id: session.user.id } });
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ ok: true });
|
|
|
|
|
}
|