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

Allow fetching a users active tournaments. Issue #4

parent ef8c9ae5
No related branches found
No related tags found
2 merge requests!20Dev,!16Resolve "Fetch tournament"
...@@ -3,8 +3,9 @@ const router = express.Router(); ...@@ -3,8 +3,9 @@ const router = express.Router();
const mongo = require("mongodb"); const mongo = require("mongodb");
const MongoClient = mongo.MongoClient; const MongoClient = mongo.MongoClient;
const connectionUrl = process.env.MONGO_CONNECTION_STRING; const connectionUrl = process.env.MONGO_CONNECTION_STRING;
/*
router.post("/new/:host/:games/:name/:tpr/:players/:rpg", (req, res) => { router.get("/playeractive/:userid", (req, res) => {
// Connect to database
MongoClient.connect( MongoClient.connect(
connectionUrl, connectionUrl,
{ useNewUrlParser: true, useUnifiedTopology: true }, { useNewUrlParser: true, useUnifiedTopology: true },
...@@ -15,37 +16,28 @@ router.post("/new/:host/:games/:name/:tpr/:players/:rpg", (req, res) => { ...@@ -15,37 +16,28 @@ router.post("/new/:host/:games/:name/:tpr/:players/:rpg", (req, res) => {
return; return;
} }
const games = req.params.games.split("&"); // Using the database gameWare and collection tournaments
const db = client.db("gameWare"); const db = client.db("gameWare");
const collection = "tournaments"; const collection = "tournaments";
const tournamentid;
db.collection(collection).insertOne( const id = mongo.ObjectId(req.params.userid);
{
gameid: req.body.gameid, db.collection(collection)
players: [req.body.userid], .find({
games: "todo", _id: id,
name: req.body.name, active: true
timePerRound: parseInt(req.body.timePerRound), })
maxPlayers: parseInt(req.body.maxPlayers), .toArray((err, result) => {
roundsPerGame: parseInt(req.body.roundsPerGame),
currentRound: 1,
dateCreated: new Date()
},
(err, result) => {
if (err) { if (err) {
res.sendStatus(500); // Internal server error res.sendStatus(500);
//console.log(err);
return; return;
} }
tournamentid = result._id; res.json(result);
});
} }
); );
db.collection("rounds").insertOne( });
{
} // 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