danwh
This commit is contained in:
@@ -178,9 +178,21 @@ router.get("/games/:id", asyncHandler(async (req, res) => {
|
|||||||
const gameId = parseInt(req.params.id, 10);
|
const gameId = parseInt(req.params.id, 10);
|
||||||
if (isNaN(gameId)) throw new ApiError(400, "Invalid game ID");
|
if (isNaN(gameId)) throw new ApiError(400, "Invalid game ID");
|
||||||
|
|
||||||
const [rows] = await pool.query("SELECT * FROM current_games WHERE id = ?", [gameId]);
|
const [games] = await pool.query("SELECT * FROM current_games WHERE id = ?", [gameId]);
|
||||||
if (!rows.length) throw new ApiError(404, "Game not found");
|
if (!games.length) throw new ApiError(404, "Game not found");
|
||||||
res.json(rows[0]);
|
|
||||||
|
const [creatorRows] = await pool.query(
|
||||||
|
`SELECT u.id, u.username
|
||||||
|
FROM game_players gp
|
||||||
|
JOIN users u ON gp.user = u.id
|
||||||
|
WHERE gp.game = ? AND gp.is_creator = TRUE
|
||||||
|
LIMIT 1`,
|
||||||
|
[gameId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const creator = creatorRows.lenght ? creatorRows[0] : null;
|
||||||
|
|
||||||
|
res.json({ ...games[0], creator});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,6 +85,15 @@ const migrations = [
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add_unique_constraint_game_players",
|
||||||
|
up: async (conn) => {
|
||||||
|
await conn.query(`
|
||||||
|
ALTER TABLE game_players
|
||||||
|
ADD CONSTRAINT uniq_game_user UNIQUE (game, user);
|
||||||
|
`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user