Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
fa0faa53
Commit
fa0faa53
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
editgame faction bug wip
parent
ecf9e6ea
No related branches found
No related tags found
3 merge requests
!59
Development to master
,
!36
Development
,
!32
Game state
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/game/game.controller.ts
+1
-0
1 addition, 0 deletions
src/game/game.controller.ts
src/game/game.dto.ts
+3
-0
3 additions, 0 deletions
src/game/game.dto.ts
src/game/game.service.ts
+36
-23
36 additions, 23 deletions
src/game/game.service.ts
with
40 additions
and
23 deletions
src/game/game.controller.ts
+
1
−
0
View file @
fa0faa53
...
...
@@ -35,6 +35,7 @@ export class GameController {
@
GameStates
(
'
CREATED
'
)
@
UsePipes
(
new
ValidationPipe
())
async
editGame
(@
Param
(
'
id
'
)
id
:
string
,
@
Body
()
body
:
GameDTO
)
{
body
.
id
=
id
;
return
this
.
gameservice
.
editGame
(
id
,
body
);
}
...
...
This diff is collapsed.
Click to expand it.
src/game/game.dto.ts
+
3
−
0
View file @
fa0faa53
...
...
@@ -11,6 +11,7 @@ import {
Allow
,
IsUUID
,
IsIn
,
IsOptional
,
}
from
'
class-validator
'
;
import
{
ObjectivePointEntity
}
from
'
./game.entity
'
;
...
...
@@ -20,6 +21,8 @@ import { CenterDTO, NodeSettingsDTO } from './game.json.dto';
import
{
Type
}
from
'
class-transformer
'
;
export
class
GameDTO
{
@
IsOptional
()
id
:
string
;
@
IsString
()
@
IsNotEmpty
()
@
Length
(
3
,
30
)
...
...
This diff is collapsed.
Click to expand it.
src/game/game.service.ts
+
36
−
23
View file @
fa0faa53
...
...
@@ -55,32 +55,41 @@ export class GameService {
}
// edit already created game
async
editGame
(
id
:
string
,
gameData
:
GameDTO
)
{
async
editGame
(
id
,
gameData
:
GameDTO
)
{
// checks if a game with the same name exists already
if
(
await
this
.
gameRepository
.
findOne
({
name
:
gameData
.
name
,
id
:
Not
(
id
)
})
)
{
throw
new
HttpException
(
'
Game already exists
'
,
HttpStatus
.
BAD_REQUEST
);
throw
new
HttpException
(
'
Game with the same name already exists
'
,
HttpStatus
.
BAD_REQUEST
,
);
}
// update game entry in db
let
factions
=
await
this
.
factionRepository
.
find
({
game
:
id
});
const
updatedGame
=
await
this
.
gameRepository
.
create
(
gameData
);
updatedGame
[
'
id
'
]
=
id
;
const
gameId
=
await
this
.
gameRepository
.
save
(
updatedGame
);
// get all the factions that are associated with the game to deny duplicate entries
const
factions
=
await
this
.
factionRepository
.
find
({
game
:
gameId
});
const
factionNames
=
factions
.
map
(({
factionName
})
=>
factionName
);
// add the factions to db
// delete removed factions
// update/insert factions
if
(
gameData
.
factions
)
{
gameData
.
factions
.
map
(
async
faction
=>
{
if
(
!
Object
.
values
(
factionNames
).
includes
(
faction
.
factionName
))
{
let
name
=
await
this
.
factionRepository
.
create
({
...
faction
,
game
:
gameId
,
});
await
this
.
factionRepository
.
insert
(
name
);
const
factionNames
=
gameData
.
factions
.
map
(
({
factionName
})
=>
factionName
,
);
const
factionIds
=
gameData
.
factions
.
map
(({
factionId
})
=>
faction
Id
);
factions
.
map
(
async
faction
=>
{
if
(
!
factionNames
.
includes
(
faction
.
factionName
))
{
await
this
.
factionRepository
.
delete
(
faction
);
}
});
gameData
.
factions
.
map
(
async
faction
=>
{
let
name
=
await
this
.
factionRepository
.
create
({
...
faction
,
game
:
gameId
,
});
await
this
.
factionRepository
.
save
(
name
);
});
}
else
{
await
this
.
factionRepository
.
delete
({
game
:
id
});
}
// get old flagboxes to deny duplicate entries
...
...
@@ -114,14 +123,18 @@ export class GameService {
}
async
updateGameStatus
(
game
:
GameStateDTO
)
{
const
updatedGame
=
await
this
.
gameRepository
.
create
(
game
);
await
this
.
gameRepository
.
save
(
updatedGame
);
// notify players about game state change
this
.
notificationGateway
.
server
.
emit
(
game
.
id
,
'
event update
'
);
return
{
code
:
200
,
message
:
'
State was updated
'
,
};
const
updatedGame
=
await
this
.
gameRepository
.
findOne
({
id
:
game
.
id
});
if
(
updatedGame
)
{
updatedGame
.
state
=
game
.
state
;
await
this
.
gameRepository
.
save
(
updatedGame
);
// notify players about game state change
this
.
notificationGateway
.
server
.
emit
(
game
.
id
,
'
event update
'
);
return
{
code
:
200
,
message
:
'
State was updated
'
,
};
}
throw
new
HttpException
(
"
Game doesn't exist
"
,
HttpStatus
.
BAD_REQUEST
);
}
async
listFactions
(
game
:
GameEntity
)
{
...
...
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