Skip to content
Snippets Groups Projects
Commit 6c584f2f authored by Tobias Ørstad's avatar Tobias Ørstad
Browse files

Allow fetching a users non active tournaments. Issue #4

parent 8faf56b6
No related branches found
No related tags found
2 merge requests!20Dev,!16Resolve "Fetch tournament"
......@@ -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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment