From 7ebc49eea25807fbe269b160f4daf23d84d2351f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20=C3=98rstad?= <tobiasio@ntnu.no>
Date: Fri, 17 Apr 2020 16:03:42 +0200
Subject: [PATCH] final fixes to alerts

---
 backend/api/rounds.js     |  2 +-
 backend/api/tournament.js | 40 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/backend/api/rounds.js b/backend/api/rounds.js
index 53423a2..f4390c2 100644
--- a/backend/api/rounds.js
+++ b/backend/api/rounds.js
@@ -449,7 +449,7 @@ function roundcheck(client, tournament, roundid) {
         // fetched the round objects of the active round
         let activePlayer;
         for (let i = 0; i < rounds.length; i++) {
-          if (rounds[i]._id.str == roundid.str) {
+          if (String(rounds[i]._id) == String(roundid)) {
             activePlayer = rounds[i].playerId;
             break;
           }
diff --git a/backend/api/tournament.js b/backend/api/tournament.js
index 4a34e49..38fada7 100644
--- a/backend/api/tournament.js
+++ b/backend/api/tournament.js
@@ -309,6 +309,46 @@ router.get("/playeractive/:userid", (req, res) => {
   );
 });
 
+router.get("/specific/:id", (req, res) => {
+  MongoClient.connect(
+    connectionUrl,
+    { useNewUrlParser: true, useUnifiedTopology: true },
+    (err, client) => {
+      // Unable to connect to database
+      if (err) {
+        res.sendStatus(500); // Internal server error
+        return;
+      }
+      let id;
+      if (!req.params.id) {
+        res.sendStatus(400);
+      }
+      try {
+        id = mongo.ObjectID(req.params.id);
+      } catch (err) {
+        res.sendStatus(400);
+      }
+      // Using the database gameWare and collection tournaments
+      const db = client.db("gameWare");
+      const collection = "tournaments";
+
+      db.collection(collection)
+        .find({
+          _id: id,
+        })
+        .toArray((err, result) => {
+          if (err) {
+            res.sendStatus(500);
+            client.close();
+            return;
+          }
+          res.json(result[0]);
+          client.close();
+        });
+    }
+  );
+});
+
 router.get("/player/:userid/:active", (req, res) => {
   // Returns the tournaments of player with active field matching parameter
   // Also checks the state of all tournaments
-- 
GitLab