From 536160bba6c6f7f3f6773828df39828199738747 Mon Sep 17 00:00:00 2001 From: Michess Date: Wed, 15 Apr 2026 07:32:57 +0200 Subject: [PATCH] feat(elo): add ELO rating system - DB: elo column on user table (default 1200, added via ALTER TABLE IF NOT EXISTS) - ELO calculated after every game save (K=32, min 100) - Bots use their fixed ELO values; only human players' ELO changes - AI page games save with bot name (e.g. 'Holzpferd Heinz') instead of 'Stockfish' - User profile shows ELO badge below name - Header shows current ELO for logged-in users (links to profile) Co-Authored-By: Claude Sonnet 4.6 --- client/src/app/ai/page.tsx | 2 +- client/src/app/user/[name]/page.tsx | 7 +++- client/src/components/Header.tsx | 5 +++ server/src/controllers/auth.controller.ts | 1 + server/src/controllers/users.controller.ts | 3 +- server/src/db/index.ts | 1 + server/src/db/models/game.model.ts | 39 ++++++++++++++++++++++ server/src/db/models/user.model.ts | 16 ++++----- server/src/routes/ai.route.ts | 4 +-- types/index.d.ts | 1 + 10 files changed, 66 insertions(+), 13 deletions(-) diff --git a/client/src/app/ai/page.tsx b/client/src/app/ai/page.tsx index d9e1ec7..c7677f7 100644 --- a/client/src/app/ai/page.tsx +++ b/client/src/app/ai/page.tsx @@ -42,7 +42,7 @@ export default function AiGamePage() { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ pgn: g.pgn(), winner, endReason, playerColor: color, level, startedAt: startedAtRef.current }) + body: JSON.stringify({ pgn: g.pgn(), winner, endReason, playerColor: color, level, botName: selectedBot.name, startedAt: startedAtRef.current }) }); if (res.ok) { const { id } = await res.json(); diff --git a/client/src/app/user/[name]/page.tsx b/client/src/app/user/[name]/page.tsx index 78cecb9..6ef48e3 100644 --- a/client/src/app/user/[name]/page.tsx +++ b/client/src/app/user/[name]/page.tsx @@ -43,7 +43,12 @@ export default async function Profile({ params }: { params: { name: string } }) return (
-

{data.name}

+
+

{data.name}

+ {data.elo != null && ( + {data.elo} ELO + )} +
Wins diff --git a/client/src/components/Header.tsx b/client/src/components/Header.tsx index c9423db..4dabb5e 100644 --- a/client/src/components/Header.tsx +++ b/client/src/components/Header.tsx @@ -37,6 +37,11 @@ export default function Header() { )} {user?.id && typeof user.id === "number" && } + {user?.elo != null && typeof user.id === "number" && ( + + {user.elo} + + )}