diff --git a/backend/api/tournament.js b/backend/api/tournament.js index 9e1837d1bebf946c5f6693de085b4d2e4c82961f..15367a154b7c2d241f56b1ea26f3a2abc55f5946 100644 --- a/backend/api/tournament.js +++ b/backend/api/tournament.js @@ -39,5 +39,40 @@ router.get("/playeractive/:userid", (req, res) => { ); }); +router.get("/player/:userid/:active", (req, res) => { + // Connect to database + MongoClient.connect( + connectionUrl, + { useNewUrlParser: true, useUnifiedTopology: true }, + (err, client) => { + // Unable to connect to database + if (err) { + res.sendStatus(500); // Internal server error + return; + } + + // Using the database gameWare and collection tournaments + const db = client.db("gameWare"); + const collection = "tournaments"; + + const id = mongo.ObjectId(req.params.userid); + + db.collection(collection) + .find({ + _id: id, + active: req.params.active === "true" + }) + .toArray((err, result) => { + if (err) { + res.sendStatus(500); + //console.log(err); + return; + } + res.json(result); + }); + } + ); +}); + // Export API routes module.exports = router;