Skip to content

Commit

Permalink
app models game.server: fix same category name across rounds
Browse files Browse the repository at this point in the history
Games were being inserted into the database incorrectly when two categories in
different rounds had the same name.

Closes #60.
  • Loading branch information
cmnord committed Feb 21, 2024
1 parent 2012630 commit b887de4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/game.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function dbGameToGame(dbGame: DbGame, categories: CategoryAndClues[]): Game {
}

for (const category of categories) {
if (!category.clues) {
if (category.clues == null || category.clues.length === 0) {
throw new Error("category must have at least one clue");
}
const round = category.round;
Expand Down Expand Up @@ -392,7 +392,9 @@ export async function createGame(
for (let round = 0; round < inputGame.boards.length; round++) {
const board = inputGame.boards[round];
for (const category of board.categories) {
const dbCategory = categoryData.find((c) => c.name === category.name);
const dbCategory = categoryData.find(
(c) => c.name === category.name && c.round == round,
);
if (!dbCategory) {
throw new Error(
"category " + category.name + " not inserted into database",
Expand Down

0 comments on commit b887de4

Please sign in to comment.