diff --git a/backend/api/tournament.js b/backend/api/tournament.js index a4122e13b11c55a3a95cb28bea2bc26528f7c069..9e1837d1bebf946c5f6693de085b4d2e4c82961f 100644 --- a/backend/api/tournament.js +++ b/backend/api/tournament.js @@ -3,8 +3,9 @@ const router = express.Router(); const mongo = require("mongodb"); const MongoClient = mongo.MongoClient; 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( connectionUrl, { useNewUrlParser: true, useUnifiedTopology: true }, @@ -15,37 +16,28 @@ router.post("/new/:host/:games/:name/:tpr/:players/:rpg", (req, res) => { return; } - const games = req.params.games.split("&"); - + // Using the database gameWare and collection tournaments const db = client.db("gameWare"); const collection = "tournaments"; - const tournamentid; - db.collection(collection).insertOne( - { - gameid: req.body.gameid, - players: [req.body.userid], - games: "todo", - name: req.body.name, - timePerRound: parseInt(req.body.timePerRound), - maxPlayers: parseInt(req.body.maxPlayers), - roundsPerGame: parseInt(req.body.roundsPerGame), - currentRound: 1, - dateCreated: new Date() - }, - (err, result) => { + const id = mongo.ObjectId(req.params.userid); + + db.collection(collection) + .find({ + _id: id, + active: true + }) + .toArray((err, result) => { if (err) { - res.sendStatus(500); // Internal server error + res.sendStatus(500); + //console.log(err); return; } - tournamentid = result._id; - } - ); - db.collection("rounds").insertOne( - { - - } - ) + res.json(result); + }); } ); -});*/ +}); + +// Export API routes +module.exports = router;