replace all current_games with games
This commit is contained in:
@@ -185,7 +185,7 @@ router.post("/users", asyncHandler(async (req, res) => {
|
||||
* turn_order: null
|
||||
*/
|
||||
router.get("/games", async (req, res) => {
|
||||
const [rows] = await pool.query("SELECT * FROM current_games");
|
||||
const [rows] = await pool.query("SELECT * FROM games");
|
||||
res.json(rows);
|
||||
});
|
||||
|
||||
@@ -217,7 +217,7 @@ router.get("/games/:id", asyncHandler(async (req, res) => {
|
||||
const gameId = parseInt(req.params.id, 10);
|
||||
if (isNaN(gameId)) throw new ApiError(400, "Invalid game ID");
|
||||
|
||||
const [games] = await pool.query("SELECT * FROM current_games WHERE id = ?", [gameId]);
|
||||
const [games] = await pool.query("SELECT * FROM games WHERE id = ?", [gameId]);
|
||||
if (!games.length) throw new ApiError(404, "Game not found");
|
||||
|
||||
const [creatorRows] = await pool.query(
|
||||
@@ -266,7 +266,7 @@ router.post("/games", asyncHandler(async (req, res) => {
|
||||
await conn.beginTransaction();
|
||||
|
||||
const [gameResult] = await conn.query(
|
||||
"INSERT INTO current_games (is_open, is_local) VALUES (?, ?)",
|
||||
"INSERT INTO games (is_open, is_local) VALUES (?, ?)",
|
||||
[true, is_local]
|
||||
);
|
||||
|
||||
@@ -277,7 +277,7 @@ router.post("/games", asyncHandler(async (req, res) => {
|
||||
[gameId, user, true]
|
||||
);
|
||||
|
||||
const [gameRow] = await conn.query("SELECT * FROM current_games WHERE id = ?", [gameId]);
|
||||
const [gameRow] = await conn.query("SELECT * FROM games WHERE id = ?", [gameId]);
|
||||
const [players] = await conn.query(
|
||||
`SELECT u.id, u.username FROM game_players gp
|
||||
JOIN users u ON gp.user = u.id
|
||||
@@ -339,7 +339,7 @@ router.post("/games/:id/players", asyncHandler(async (req, res) => {
|
||||
if (alreadyJoined.length) throw new ApiError(400, "User already joined this game");
|
||||
|
||||
const [gameRows] = await conn.query(
|
||||
"SELECT * FROM current_games WHERE id = ? AND is_open = TRUE",// AND is_local = FALSE", TODO: wehn im body der richtige creator angegeben wurde wir user zu dem local game hinzugefügt
|
||||
"SELECT * FROM games WHERE id = ? AND is_open = TRUE",// AND is_local = FALSE", TODO: wehn im body der richtige creator angegeben wurde wir user zu dem local game hinzugefügt
|
||||
[gameId]
|
||||
);
|
||||
|
||||
@@ -426,7 +426,7 @@ router.patch("/games/:id/lock", asyncHandler(async (req, res) => {
|
||||
|
||||
const currentPlayingUser = turnOrder[0];
|
||||
await conn.query(
|
||||
"UPDATE current_games SET is_open = FALSE, turn_order = ?, current_playing_user = ? WHERE id = ?",
|
||||
"UPDATE games SET is_open = FALSE, turn_order = ?, current_playing_user = ? WHERE id = ?",
|
||||
[JSON.stringify(turnOrder), currentPlayingUser, gameId]
|
||||
);
|
||||
|
||||
@@ -575,7 +575,7 @@ router.post("/games/:id/turns", asyncHandler(async (req, res) => {
|
||||
await conn.beginTransaction();
|
||||
|
||||
const [gameRows] = await conn.query(
|
||||
"SELECT current_playing_user, turn_order FROM current_games WHERE id = ? FOR UPDATE",
|
||||
"SELECT current_playing_user, turn_order FROM games WHERE id = ? FOR UPDATE",
|
||||
[gameId]
|
||||
);
|
||||
|
||||
@@ -598,7 +598,7 @@ router.post("/games/:id/turns", asyncHandler(async (req, res) => {
|
||||
const nextPlayer = turnOrder[nextIndex];
|
||||
|
||||
await conn.query(
|
||||
"UPDATE current_games SET current_playing_user = ? WHERE id = ?",
|
||||
"UPDATE games SET current_playing_user = ? WHERE id = ?",
|
||||
[nextPlayer, gameId]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user