Skip to content

Commit

Permalink
If you can't find a cbit = 0 game, also look for cbit = 1 (e.g. if yo…
Browse files Browse the repository at this point in the history
…ur opponent finished your game, but you just refresh your browser window)
  • Loading branch information
pvanwamelen committed Oct 21, 2023
1 parent 771e7ae commit dc4adbc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions api/abstractplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,24 @@ async function game(userid: string, pars: { id: string, cbit: string | number, m
}));

const gameData = await getGame;
const game = gameData.Item as FullGame;
if (game === undefined)
throw new Error(`Game ${pars.id}, metaGame ${pars.metaGame}, completed bit ${pars.cbit} not found`);
let game = gameData.Item as FullGame;
if (game === undefined) {
// Maybe the game has ended and we need to look for the completed game.
if (pars.cbit === 0) {
const completedGameData = await ddbDocClient.send(
new GetCommand({
TableName: process.env.ABSTRACT_PLAY_TABLE,
Key: {
"pk": "GAME",
"sk": pars.metaGame + "#1#" + pars.id
},
}));
game = completedGameData.Item as FullGame;
}
if (game === undefined) {
throw new Error(`Game ${pars.id}, metaGame ${pars.metaGame}, completed bit ${pars.cbit} not found`);
}
}
// If the game is over update user to indicate they have seen the game end.
let work;
if ((game.toMove === "" || game.toMove === null) && userid !== "") {
Expand Down

0 comments on commit dc4adbc

Please sign in to comment.