akhy profile and games history

This commit is contained in:
Milo
2025-08-25 17:06:36 +02:00
parent d283fa405c
commit f965eab242
4 changed files with 13 additions and 4 deletions

View File

@@ -105,7 +105,7 @@ stmtGames.run()
export const insertGame = flopoDB.prepare('INSERT INTO games (id, p1, p2, p1_score, p2_score, p1_elo, p2_elo, p1_new_elo, p2_new_elo, type, timestamp) VALUES (@id, @p1, @p2, @p1_score, @p2_score, @p1_elo, @p2_elo, @p1_new_elo, @p2_new_elo, @type, @timestamp)');
export const getGames = flopoDB.prepare('SELECT * FROM games');
export const getUserGames = flopoDB.prepare('SELECT * FROM games WHERE p1 = @user_id OR p2 = @user_id');
export const getUserGames = flopoDB.prepare('SELECT * FROM games WHERE p1 = @user_id OR p2 = @user_id ORDER BY timestamp DESC');
export const stmtElos = flopoDB.prepare(`

View File

@@ -125,6 +125,15 @@ export function apiRoutes(client, io) {
}
});
router.get('/user/:id/games-history', async (req, res) => {
try {
const games = getUserGames.all({ user_id: req.params.id });
res.json({ games })
} catch (err) {
res.status(500).json({ error: 'Failed to fetch games history.' });
}
})
router.get('/user/:id/daily', async (req, res) => {
const { id } = req.params;
try {

View File

@@ -281,7 +281,7 @@ async function joinRoom(roomId, userId, io) {
const room = pokerRooms[roomId];
const playerObject = {
id: userId, globalName: user.globalName || user.username,
id: userId, globalName: user.globalName || user.username, avatar: user.displayAvatarURL({ dynamic: true, size: 256 }),
hand: [], bank: room.minBet, bet: 0, folded: false, allin: false,
last_played_turn: null, solve: null
};

View File

@@ -191,9 +191,9 @@ async function createGame(client, gameType) {
let lobby;
if (gameType === 'tictactoe') {
lobby = { p1: { id: p1Id, name: p1.globalName, val: 'X' }, p2: { id: p2Id, name: p2.globalName, val: 'O' }, sum: 1, xs: [], os: [], gameOver: false, lastmove: Date.now() };
lobby = { p1: { id: p1Id, name: p1.globalName, val: 'X', avatar: p1.displayAvatarURL({ dynamic: true, size: 256 }) }, p2: { id: p2Id, name: p2.globalName, val: 'O', avatar: p2.displayAvatarURL({ dynamic: true, size: 256 }) }, sum: 1, xs: [], os: [], gameOver: false, lastmove: Date.now() };
} else { // connect4
lobby = { p1: { id: p1Id, name: p1.globalName, val: 'R' }, p2: { id: p2Id, name: p2.globalName, val: 'Y' }, turn: p1Id, board: createConnect4Board(), gameOver: false, lastmove: Date.now(), winningPieces: [] };
lobby = { p1: { id: p1Id, name: p1.globalName, val: 'R', avatar: p1.displayAvatarURL({ dynamic: true, size: 256 }) }, p2: { id: p2Id, name: p2.globalName, val: 'Y', avatar: p2.displayAvatarURL({ dynamic: true, size: 256 }) }, turn: p1Id, board: createConnect4Board(), gameOver: false, lastmove: Date.now(), winningPieces: [] };
}
const msgId = await updateDiscordMessage(client, lobby, title);