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
b88c2a0d
Commit
b88c2a0d
authored
5 years ago
by
Ronnie Friman
Browse files
Options
Downloads
Patches
Plain Diff
fixed gamedit bug with duplicate factions/flagboxes
parent
35885d31
No related branches found
No related tags found
3 merge requests
!59
Development to master
,
!36
Development
,
!32
Game state
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/game/game.service.ts
+28
-23
28 additions, 23 deletions
src/game/game.service.ts
with
28 additions
and
23 deletions
src/game/game.service.ts
+
28
−
23
View file @
b88c2a0d
...
...
@@ -65,22 +65,27 @@ export class GameService {
HttpStatus
.
BAD_REQUEST
,
);
}
// update game entry in db
// get factions that have been added previously
let
factions
=
await
this
.
factionRepository
.
find
({
game
:
id
});
// get flagboxes that have been added previously
let
flagboxes
=
await
this
.
objectivePointRepository
.
find
({
game
:
id
,
});
console
.
log
(
flagboxes
);
// update game entry in db
const
updatedGame
=
await
this
.
gameRepository
.
create
(
gameData
);
const
gameId
=
await
this
.
gameRepository
.
save
(
updatedGame
);
// delete removed factions
// update/insert factions
// iterate factions if any were added
if
(
gameData
.
factions
)
{
const
factionNames
=
gameData
.
factions
.
map
(
({
factionName
})
=>
factionName
,
);
const
factionIds
=
gameData
.
factions
.
map
(({
factionId
})
=>
factionId
);
// delete all existing factions that are not in submitted data
factions
.
map
(
async
faction
=>
{
if
(
!
faction
Name
s
.
includes
(
faction
.
faction
Name
))
{
if
(
!
faction
Id
s
.
includes
(
faction
.
faction
Id
))
{
await
this
.
factionRepository
.
delete
(
faction
);
}
});
// create / update factions present in the submitted data
gameData
.
factions
.
map
(
async
faction
=>
{
let
name
=
await
this
.
factionRepository
.
create
({
...
faction
,
...
...
@@ -89,29 +94,29 @@ export class GameService {
await
this
.
factionRepository
.
save
(
name
);
});
}
else
{
// if no factions are present in data, delete all factions associated with the game
await
this
.
factionRepository
.
delete
({
game
:
id
});
}
// get old flagboxes to deny duplicate entries
const
flagboxes
=
await
this
.
objectivePointRepository
.
find
({
game
:
gameId
,
});
const
flagboxIds
=
flagboxes
.
map
(
({
objectivePointDescription
})
=>
objectivePointDescription
,
);
// insert the flagboxes to db
if
(
gameData
.
objective_points
)
{
gameData
.
objective_points
.
map
(
async
flagbox
=>
{
if
(
!
Object
.
values
(
flagboxIds
).
includes
(
flagbox
.
objectivePointDescription
)
)
{
let
newFlagbox
=
await
this
.
objectivePointRepository
.
create
({
...
flagbox
,
game
:
gameId
,
});
await
this
.
objectivePointRepository
.
insert
(
newFlagbox
);
const
flagboxIds
=
gameData
.
objective_points
.
map
(
({
objectivePointId
})
=>
objectivePointId
,
);
flagboxes
.
map
(
async
flagbox
=>
{
if
(
!
flagboxIds
.
includes
(
flagbox
.
objectivePointDescription
))
{
await
this
.
objectivePointRepository
.
delete
(
flagbox
);
}
});
gameData
.
objective_points
.
map
(
async
flagbox
=>
{
let
newFlagbox
=
await
this
.
objectivePointRepository
.
create
({
...
flagbox
,
game
:
gameId
,
});
await
this
.
objectivePointRepository
.
save
(
newFlagbox
);
});
}
else
{
await
this
.
objectivePointRepository
.
delete
({
game
:
id
});
}
// TO DO: ADD FLAGBOX LOCATION TO MAPDRAWING ENTITY
...
...
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