Fix SQL query to get completed games
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 16 Mar 2020 19:27:55 +0000 (20:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 16 Mar 2020 19:27:55 +0000 (20:27 +0100)
server/models/Game.js

index 080cab3..641c0dc 100644 (file)
@@ -232,11 +232,18 @@ const GameModel =
         "JOIN Variants v " +
         "  ON g.vid = v.id " +
         "WHERE " +
-        "  score <> '*' AND " +
-        "  created < " + cursor + " AND " +
+        "  score <> '*' AND" +
+        "  created < " + cursor + " AND" +
         "  (" +
-        "    (" + uid + " = white AND NOT deletedByWhite) OR " +
-        "    (" + uid + " = black AND NOT deletedByBlack)" +
+        "    (" +
+        "      white = " + uid + " AND" +
+        "      (deletedByWhite IS NULL OR NOT deletedByWhite)" +
+        "    )" +
+        "    OR " +
+        "    (" +
+        "      black = " + uid + " AND" +
+        "      (deletedByBlack IS NULL OR NOT deletedByBlack)" +
+        "    )" +
         "  ) ";
       query +=
         "ORDER BY created DESC " +