aboutsummaryrefslogtreecommitdiffstats
path: root/backend/src/routes/score.ts
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/routes/score.ts')
-rw-r--r--backend/src/routes/score.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/backend/src/routes/score.ts b/backend/src/routes/score.ts
index 168629a..a10833d 100644
--- a/backend/src/routes/score.ts
+++ b/backend/src/routes/score.ts
@@ -141,6 +141,33 @@ export const handleScoreUpload = async (
}
};
+export const handleExportScoreForGame = async (
+ req: express.Request,
+ res: express.Response,
+) => {
+ const { internalGameName, page } = req.query;
+ const userId = req.session.userId;
+ if (!userId || !internalGameName) {
+ return res.status(400).json({ error: "Missing required parameters" });
+ }
+ const offset = (Math.max(parseInt(page as string) || 1, 1) - 1) * 50;
+ const scores: any = await prisma.$queryRaw`
+ SELECT * FROM "Score"
+ WHERE "userId" = ${userId}
+ AND "gameInternalName" = ${internalGameName}
+ ORDER BY (data->>'timestamp')::numeric desc
+ OFFSET ${offset} LIMIT 50
+ `;
+ const safeScores = scores.map((score: any) => ({
+ ...score,
+ timestamp: typeof score.timestamp === "bigint" ? Number(score.timestamp) : score.timestamp,
+ }));
+
+ res.status(200).json({
+ scores: safeScores,
+ });
+};
+
export const handleScoreDeletion = async (
req: express.Request,
res: express.Response,
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage