Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Progark gruppe 3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Ingebrigt Ørstad
Progark gruppe 3
Merge requests
!11
Resolve "Post tournament"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Post tournament"
7-post-tournament-2
into
dev
Overview
0
Commits
2
Pipelines
0
Changes
2
Merged
Tobias Ingebrigt Ørstad
requested to merge
7-post-tournament-2
into
dev
5 years ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
Closes
#7 (closed)
Edited
5 years ago
by
Tobias Ingebrigt Ørstad
0
0
Merge request reports
Compare
dev
version 1
35ed2b61
5 years ago
dev (base)
and
latest version
latest version
3448198a
2 commits,
5 years ago
version 1
35ed2b61
1 commit,
5 years ago
2 files
+
40
−
18
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
backend/api/tournament.js
+
39
−
17
Options
@@ -3,8 +3,8 @@ 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
.
post
(
"
/new
"
,
(
req
,
res
)
=>
{
MongoClient
.
connect
(
connectionUrl
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
},
@@ -15,37 +15,59 @@ router.post("/new/:host/:games/:name/:tpr/:players/:rpg", (req, res) => {
return
;
}
const games = req.params.games.split("&");
const
db
=
client
.
db
(
"
gameWare
"
);
const
collection
=
"
tournaments
"
;
const tournamentid;
let
tournamentid
;
const
tournamentdate
=
new
Date
();
let
tournyresult
;
db
.
collection
(
collection
).
insertOne
(
{
gameid: req.body.gameid,
players: [req.body.userid],
games: "todo",
players
:
[
mongo
.
ObjectID
(
req
.
body
.
userid
)],
games
:
req
.
body
.
games
,
name
:
req
.
body
.
name
,
timePerRound
:
parseInt
(
req
.
body
.
timePerRound
),
maxPlayers
:
parseInt
(
req
.
body
.
maxPlayers
),
roundsPerGame
:
parseInt
(
req
.
body
.
roundsPerGame
),
currentRound
:
1
,
dateCreated:
new D
ate
()
dateCreated
:
tournamentd
ate
},
(
err
,
result
)
=>
{
if
(
err
)
{
res
.
sendStatus
(
500
);
// Internal server error
return
;
}
tournamentid = result._id;
tournamentid
=
result
.
insertedId
;
// Save id of inserted tournament to be used as reference for first round entity
tournyresult
=
result
;
// Save result to be given as response to finished request
tournamentdate
.
setTime
(
tournamentdate
.
getTime
()
+
req
.
body
.
timePerRound
*
60
*
60
*
1000
);
createFirstRound
(
tournamentid
,
result
,
tournamentdate
);
}
);
db.collection("rounds").insertOne(
{
}
)
//Function for creating first round of tournament for hosting player
function
createFirstRound
(
tournyid
,
tournyresult
,
date
)
{
db
.
collection
(
"
rounds
"
).
insertOne
(
{
tournamentId
:
mongo
.
ObjectID
(
tournyid
),
playerId
:
mongo
.
ObjectID
(
req
.
body
.
userid
),
gameId
:
mongo
.
ObjectID
(
req
.
body
.
games
[
0
]),
scoreValue
:
0
,
roundNr
:
1
,
hasPlayed
:
false
,
deadlineDate
:
date
},
err
=>
{
if
(
err
)
{
res
.
sendStatus
(
500
);
// Internal server error
return
;
}
res
.
json
(
tournyresult
);
}
);
}
}
);
});*/
});
module
.
exports
=
router
;
Loading