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
!22
Resolve "Join tournament"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Join tournament"
28-join-tournament
into
dev
Overview
0
Commits
3
Pipelines
0
Changes
1
Merged
Tobias Ingebrigt Ørstad
requested to merge
28-join-tournament
into
dev
5 years ago
Overview
0
Commits
3
Pipelines
0
Changes
1
Expand
Closes
#28 (closed)
0
0
Merge request reports
Compare
dev
version 1
0e3193f4
5 years ago
dev (base)
and
latest version
latest version
76c2683f
3 commits,
5 years ago
version 1
0e3193f4
2 commits,
5 years ago
1 file
+
59
−
10
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
backend/api/tournament.js
+
59
−
10
Options
@@ -85,19 +85,68 @@ router.post("/join", (req, res) => {
@@ -85,19 +85,68 @@ router.post("/join", (req, res) => {
const
db
=
client
.
db
(
"
gameWare
"
);
const
db
=
client
.
db
(
"
gameWare
"
);
const
collection
=
"
tournaments
"
;
const
collection
=
"
tournaments
"
;
db
.
collection
(
collection
)
db
.
collection
(
collection
).
findOneAndUpdate
(
.
find
({
{
$expr
:
{
$lt
:
[
"
$maxPlayers
"
,
"
$players.length
"
]
}
// the length of the array of players must be less than the maximum amount
})
$expr
:
{
$lt
:
[
"
$maxPlayers
"
,
"
$players.length
"
]
},
.
toArray
((
err
,
result
)
=>
{
currentRound
:
1
,
active
:
true
,
// the array of players cannot already contain the player
players
:
{
$nin
:
[
mongo
.
ObjectID
(
req
.
body
.
userid
)]
}
},
// Add the player to the array
{
$push
:
{
players
:
mongo
.
ObjectID
(
req
.
body
.
userid
)
}
},
{
// make sure we join the oldest tournament that matches our query.
sort
:
{
dateCreated
:
1
},
// the returned document should be the modified version
returnNewDocument
:
true
},
(
err
,
result
)
=>
{
if
(
err
)
{
if
(
err
)
{
res
.
sendStatus
(
500
);
res
.
sendStatus
(
500
);
// Internal server error
console
.
log
(
err
);
return
;
return
;
}
}
res
.
json
(
result
);
try
{
});
tournamentdate
=
result
.
value
.
dateCreated
;
db
.
collection
(
"
rounds
"
).
insertOne
({});
tournamentdate
.
setTime
(
tournamentdate
.
getTime
()
+
result
.
value
.
timePerRound
*
60
*
60
*
1000
);
// create the first round for the newly joined player
createFirstRound
(
result
.
value
.
_id
,
result
.
value
,
tournamentdate
,
req
.
body
.
userid
,
result
.
value
.
games
[
0
]
);
}
catch
(
err
)
{
res
.
json
(
404
);
// Element not found
}
}
);
//Function for creating first round of tournament for hosting player
function
createFirstRound
(
tournyid
,
tournyresult
,
date
,
userid
,
gameid
)
{
db
.
collection
(
"
rounds
"
).
insertOne
(
{
tournamentId
:
mongo
.
ObjectID
(
tournyid
),
playerId
:
mongo
.
ObjectID
(
userid
),
gameId
:
mongo
.
ObjectID
(
gameid
),
scoreValue
:
0
,
roundNr
:
1
,
hasPlayed
:
false
,
deadlineDate
:
date
},
err
=>
{
if
(
err
)
{
res
.
sendStatus
(
500
);
// Internal server error
return
;
}
res
.
json
(
tournyresult
);
}
);
}
}
}
);
);
});
});
Loading