- 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 <noreply@anthropic.com>
35 lines
965 B
TypeScript
35 lines
965 B
TypeScript
import type { Request, Response } from "express";
|
|
import xss from "xss";
|
|
|
|
import GameModel from "../db/models/game.model.js";
|
|
import UserModel from "../db/models/user.model.js";
|
|
|
|
export const getUserProfile = async (req: Request, res: Response) => {
|
|
try {
|
|
const name = xss(req.params.name);
|
|
|
|
const users = await UserModel.findByNameEmail({ name, email: name });
|
|
|
|
if (!users || !users.length) {
|
|
res.status(404).end();
|
|
return;
|
|
}
|
|
|
|
const recentGames = await GameModel.findByUserId(users[0].id as number);
|
|
|
|
const publicUser = {
|
|
id: users[0].id,
|
|
name: users[0].name,
|
|
wins: users[0].wins,
|
|
losses: users[0].losses,
|
|
draws: users[0].draws,
|
|
elo: users[0].elo
|
|
};
|
|
|
|
res.status(200).json({ ...publicUser, recentGames });
|
|
} catch (err: unknown) {
|
|
console.log(err);
|
|
res.status(500).end();
|
|
}
|
|
};
|