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
01d5aabc
Commit
01d5aabc
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
reworked draw services
parent
a737daee
No related branches found
No related tags found
3 merge requests
!59
Development to master
,
!44
Development to testing
,
!41
Draw update
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/draw/draw.controller.ts
+14
-8
14 additions, 8 deletions
src/draw/draw.controller.ts
src/draw/draw.service.ts
+32
-11
32 additions, 11 deletions
src/draw/draw.service.ts
with
46 additions
and
19 deletions
src/draw/draw.controller.ts
+
14
−
8
View file @
01d5aabc
...
@@ -7,12 +7,14 @@ import {
...
@@ -7,12 +7,14 @@ import {
UsePipes
,
UsePipes
,
ValidationPipe
,
ValidationPipe
,
Body
,
Body
,
UseInterceptors
,
ClassSerializerInterceptor
,
}
from
'
@nestjs/common
'
;
}
from
'
@nestjs/common
'
;
import
{
AuthGuard
}
from
'
../shared/auth.guard
'
;
import
{
DrawService
}
from
'
./draw.service
'
;
import
{
DrawService
}
from
'
./draw.service
'
;
import
{
Roles
,
GameStates
}
from
'
../shared/guard.decorator
'
;
import
{
Roles
,
GameStates
}
from
'
../shared/guard.decorator
'
;
import
{
MapDrawingDTO
,
ReturnDrawingsDTO
}
from
'
./mapdrawing.dto
'
;
import
{
MapDrawingDTO
}
from
'
./mapdrawing.dto
'
;
import
{
GamePerson
}
from
'
src/game/gameperson.decorator
'
;
/*
/*
DrawController
DrawController
...
@@ -29,14 +31,18 @@ export class DrawController {
...
@@ -29,14 +31,18 @@ export class DrawController {
@
Roles
(
'
admin
'
,
'
factionleader
'
)
@
Roles
(
'
admin
'
,
'
factionleader
'
)
@
GameStates
(
'
CREATED
'
,
'
STARTED
'
)
@
GameStates
(
'
CREATED
'
,
'
STARTED
'
)
@
UsePipes
(
new
ValidationPipe
())
@
UsePipes
(
new
ValidationPipe
())
async
draw
(@
Param
(
'
id
'
)
gameId
,
@
Body
()
data
:
MapDrawingDTO
)
{
async
draw
(
return
this
.
drawService
.
draw
(
gameId
,
data
);
@
GamePerson
()
gameperson
,
@
Param
(
'
id
'
)
gameId
,
@
Body
()
data
:
MapDrawingDTO
,
)
{
return
this
.
drawService
.
draw
(
gameperson
,
gameId
,
data
);
}
}
@
Get
(
'
map/:id
'
)
@
Get
(
'
map/:id
'
)
@
UseGuards
(
new
AuthGuard
()
)
@
Roles
(
'
admin
'
,
'
factionleader
'
,
'
soldier
'
,
'
groupleader
'
)
@
Use
Pipes
(
new
ValidationPipe
()
)
@
Use
Interceptors
(
ClassSerializerInterceptor
)
async
drawMap
(@
Param
(
'
id
'
)
id
,
@
Body
()
data
:
ReturnDrawingsDTO
)
{
async
drawMap
(@
GamePerson
()
gameperson
,
@
Param
(
'
id
'
)
gameId
)
{
return
this
.
drawService
.
drawMap
(
id
,
data
);
return
this
.
drawService
.
drawMap
(
gameperson
,
gameId
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/draw/draw.service.ts
+
32
−
11
View file @
01d5aabc
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
Injectable
,
HttpException
,
HttpStatus
}
from
'
@nestjs/common
'
;
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
Repository
}
from
'
typeorm
'
;
import
{
Repository
}
from
'
typeorm
'
;
import
{
MapDrawingEntity
}
from
'
../draw/coordinate.entity
'
;
import
{
MapDrawingEntity
}
from
'
../draw/coordinate.entity
'
;
import
{
MapDrawingDTO
,
ReturnDrawingsDTO
}
from
'
./mapdrawing.dto
'
;
import
{
MapDrawingDTO
}
from
'
./mapdrawing.dto
'
;
import
{
NotificationGateway
}
from
'
src/notifications/notifications.gateway
'
;
import
{
NotificationGateway
}
from
'
src/notifications/notifications.gateway
'
;
@
Injectable
()
@
Injectable
()
...
@@ -14,38 +14,59 @@ export class DrawService {
...
@@ -14,38 +14,59 @@ export class DrawService {
private
notificationGateway
:
NotificationGateway
,
private
notificationGateway
:
NotificationGateway
,
)
{}
)
{}
async
draw
(
gameId
,
data
:
MapDrawingDTO
)
{
async
draw
(
gameperson
,
gameId
,
data
:
MapDrawingDTO
)
{
data
[
'
gameId
'
]
=
gameId
;
data
[
'
gameId
'
]
=
gameId
;
const
drawing
=
await
this
.
mapDrawingRepository
.
create
(
data
);
const
drawing
=
await
this
.
mapDrawingRepository
.
create
(
data
);
this
.
notificationGateway
.
server
.
emit
(
gameId
,
{
this
.
notificationGateway
.
server
.
emit
(
gameId
,
{
type
:
'
drawing-update
'
,
type
:
'
drawing-update
'
,
});
});
// create new instance if id is null
if
(
data
.
mapDrawingId
==
null
||
data
.
mapDrawingId
==
''
)
{
if
(
data
.
mapDrawingId
==
null
||
data
.
mapDrawingId
==
''
)
{
// luo uuden instanssin.
drawing
.
faction
=
gameperson
.
faction
;
console
.
log
(
drawing
);
const
mapDrawing
=
await
this
.
mapDrawingRepository
.
insert
(
drawing
);
const
mapDrawing
=
await
this
.
mapDrawingRepository
.
insert
(
drawing
);
return
mapDrawing
.
identifiers
;
return
mapDrawing
.
identifiers
;
}
else
{
}
//päivittää mapDrawingin
// get ref from db
const
draw
=
await
this
.
mapDrawingRepository
.
findOne
({
where
:
{
mapDrawingId
:
data
.
mapDrawingId
},
relations
:
[
'
faction
'
],
});
if
(
await
draw
.
ownershipCheck
(
gameperson
.
faction
,
gameperson
.
role
))
{
// else update the existing instance
return
await
this
.
mapDrawingRepository
.
save
(
drawing
);
return
await
this
.
mapDrawingRepository
.
save
(
drawing
);
}
}
throw
new
HttpException
(
'
Drawing is not from your faction!
'
,
HttpStatus
.
BAD_REQUEST
,
);
}
}
// draw map based on game and
// draw map based on game and gameperson faction
async
drawMap
(
id
,
data
:
ReturnDrawingsDTO
)
{
async
drawMap
(
gameperson
,
gameId
)
{
// return all active drawings if admin
if
(
gameperson
.
role
===
'
admin
'
)
{
return
await
this
.
mapDrawingRepository
.
find
({
where
:
{
gameId
:
gameId
,
drawingIsActive
:
true
},
relations
:
[
'
faction
'
],
});
}
// return mapdrawings with given faction and gameid
// return mapdrawings with given faction and gameid
return
await
this
.
mapDrawingRepository
.
find
({
return
await
this
.
mapDrawingRepository
.
find
({
where
:
[
where
:
[
{
{
gameId
:
i
d
,
gameId
:
gameI
d
,
faction
:
data
.
faction
Id
,
faction
:
gameperson
.
faction
,
drawingIsActive
:
true
,
drawingIsActive
:
true
,
},
},
{
{
gameId
:
i
d
,
gameId
:
gameI
d
,
faction
:
null
,
faction
:
null
,
drawingIsActive
:
true
,
drawingIsActive
:
true
,
},
},
],
],
relations
:
[
'
faction
'
],
});
});
}
}
}
}
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