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
Commits
82c6e106
Commit
82c6e106
authored
5 years ago
by
Ivar Nordvik Myrstad
Browse files
Options
Downloads
Plain Diff
Merge branch '54-include-name-in-get-highscore' into 'dev'
Resolve "Include name in get highscore" Closes
#54
See merge request
!51
parents
12cf90bf
a2475b02
No related branches found
No related tags found
1 merge request
!51
Resolve "Include name in get highscore"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/api/highscores.js
+44
-4
44 additions, 4 deletions
backend/api/highscores.js
frontend/core/src/com/gameware/game/models/Highscore.java
+8
-1
8 additions, 1 deletion
frontend/core/src/com/gameware/game/models/Highscore.java
with
52 additions
and
5 deletions
backend/api/highscores.js
+
44
−
4
View file @
82c6e106
...
...
@@ -45,9 +45,11 @@ router.get("/gamescore/:playerId/:gameId", (req, res) => {
//console.log(err);
return
;
}
res
.
json
(
result
);
addNameToResult
(
result
,
db
).
then
(
objects
=>
{
res
.
json
(
objects
);
client
.
close
();
});
});
}
);
});
...
...
@@ -193,6 +195,7 @@ router.get("/gamescores/:gameId", (req, res) => {
if
(
gameId
==
null
)
{
res
.
status
(
400
).
send
(
"
Fields missing
"
);
return
;
}
db
.
collection
(
collection
)
...
...
@@ -208,12 +211,49 @@ router.get("/gamescores/:gameId", (req, res) => {
//console.log(err);
return
;
}
res
.
json
(
result
);
addNameToResult
(
result
,
db
).
then
(
objects
=>
{
res
.
json
(
objects
);
client
.
close
();
});
});
}
);
});
function
addNameToResult
(
result
,
db
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
playerIds
=
result
.
map
(
o
=>
o
.
playerId
);
db
.
collection
(
"
players
"
)
.
find
({
_id
:
{
$in
:
playerIds
}
})
.
project
({
name
:
1
})
.
toArray
((
err
,
nameresult
)
=>
{
if
(
err
)
{
res
.
sendStatus
(
500
);
//console.log(err);
return
;
}
nameresult
=
nameresult
.
map
(
doc
=>
{
// rename _id => playerId
doc
.
playerId
=
doc
.
_id
;
delete
doc
.
_id
;
return
doc
;
});
let
objects
=
[];
for
(
let
i
=
0
;
i
<
result
.
length
;
i
++
)
{
objects
.
push
({
...
result
[
i
],
...
nameresult
.
find
(
itmInner
=>
String
(
itmInner
.
playerId
)
===
String
(
result
[
i
].
playerId
)
)
});
}
resolve
(
objects
);
});
});
}
// Export API routes
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
frontend/core/src/com/gameware/game/models/Highscore.java
+
8
−
1
View file @
82c6e106
...
...
@@ -6,15 +6,17 @@ public class Highscore {
private
String
_id
;
private
String
gameId
;
private
String
playerId
;
private
String
name
;
private
double
value
;
public
Highscore
()
{
}
public
Highscore
(
String
_id
,
String
gameId
,
String
userId
,
double
value
)
{
public
Highscore
(
String
_id
,
String
gameId
,
String
userId
,
String
name
,
double
value
)
{
this
.
_id
=
_id
;
this
.
gameId
=
gameId
;
this
.
playerId
=
userId
;
this
.
name
=
name
;
this
.
value
=
value
;
}
...
...
@@ -30,6 +32,10 @@ public class Highscore {
return
playerId
;
}
public
String
getName
()
{
return
name
;
}
public
double
getValue
()
{
return
value
;
}
...
...
@@ -38,6 +44,7 @@ public class Highscore {
_id
=
null
;
gameId
=
null
;
playerId
=
null
;
name
=
null
;
value
=
Double
.
parseDouble
(
null
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment