aboutsummaryrefslogtreecommitdiffstats
path: root/backend/src/routes
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-10-27 22:25:44 -0700
committerPinapelz <yukais@pinapelz.com>2025-10-30 01:19:42 -0700
commit732f3873354863a4dec591d4d6a425edb7b47c61 (patch)
treeb03b2df492fdc9d9daf1c9c8cf8baff410983831 /backend/src/routes
parentaad52db138830de8b473ada5525f33164c65abab (diff)
add heatmap api endpoints and heatmap to stub profile page
Diffstat (limited to 'backend/src/routes')
-rw-r--r--backend/src/routes/user.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts
index 7db25db..fc03e68 100644
--- a/backend/src/routes/user.ts
+++ b/backend/src/routes/user.ts
@@ -46,3 +46,46 @@ export const handleGetCurrentSession = async (req: express.Request, res: expres
res.status(500).json({ error: 'Internal server error' });
}
}
+
+export const handleGetScoresHeatmap = async (req: express.Request, res: express.Response) => {
+ const { userId, gameInternalName } = req.query;
+ if (!userId) {
+ return res.status(400).json({ error: "Must specify userId to lookup parameters" });
+ }
+ try {
+ const user = await prisma.user.findUnique({
+ where: { id: parseInt(userId as string) },
+ select: { id: true, username: true, isAdmin: true }
+ });
+ if (!user) {
+ return res.status(404).json({ error: "User not found" });
+ }
+
+ const oneYearAndOneDay = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000);
+ const unixMs = Math.floor(oneYearAndOneDay.getTime() / 1000);
+
+ const scores = await prisma.score.findMany({
+ where: {
+ userId: parseInt(userId as string),
+ timestamp: { gte: unixMs },
+ ...(gameInternalName && { gameInternalName: gameInternalName as string })
+ },
+ orderBy: { timestamp: 'desc' },
+ select: {
+ timestamp: true
+ }
+ }).then(scores => scores.map(score => ({
+ ...score,
+ timestamp: Number(score.timestamp)
+ })))
+
+ res.json({
+ "username": user.username,
+ "isAdmin": user.isAdmin,
+ scores
+ });
+ } catch (error) {
+ console.error('Session check error:', error);
+ res.status(500).json({ error: 'Internal server error' });
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage