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
7b38a20d
Commit
7b38a20d
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
added DTOs for draw
parent
c5a17c37
No related branches found
Branches containing commit
No related tags found
3 merge requests
!59
Development to master
,
!36
Development
,
!33
Small fixes
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/draw/draw.controller.ts
+4
-3
4 additions, 3 deletions
src/draw/draw.controller.ts
src/draw/draw.service.ts
+17
-10
17 additions, 10 deletions
src/draw/draw.service.ts
src/draw/mapdrawing.dto.ts
+17
-16
17 additions, 16 deletions
src/draw/mapdrawing.dto.ts
with
38 additions
and
29 deletions
src/draw/draw.controller.ts
+
4
−
3
View file @
7b38a20d
...
@@ -12,6 +12,7 @@ import {
...
@@ -12,6 +12,7 @@ import {
import
{
AuthGuard
}
from
'
../shared/auth.guard
'
;
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
'
;
/*
/*
DrawController
DrawController
...
@@ -25,17 +26,17 @@ export class DrawController {
...
@@ -25,17 +26,17 @@ export class DrawController {
constructor
(
private
drawService
:
DrawService
)
{}
constructor
(
private
drawService
:
DrawService
)
{}
@
Put
(
'
mapdrawing/:id
'
)
@
Put
(
'
mapdrawing/:id
'
)
@
UsePipes
(
new
ValidationPipe
())
@
Roles
(
'
admin
'
,
'
factionleader
'
)
@
Roles
(
'
admin
'
,
'
factionleader
'
)
@
GameStates
(
'
CREATED
'
,
'
STARTED
'
)
@
GameStates
(
'
CREATED
'
,
'
STARTED
'
)
async
draw
(@
Param
(
'
id
'
)
gameId
,
@
Body
()
data
)
{
@
UsePipes
(
new
ValidationPipe
())
async
draw
(@
Param
(
'
id
'
)
gameId
,
@
Body
()
data
:
MapDrawingDTO
)
{
return
this
.
drawService
.
draw
(
gameId
,
data
);
return
this
.
drawService
.
draw
(
gameId
,
data
);
}
}
@
Get
(
'
map/:id
'
)
@
Get
(
'
map/:id
'
)
@
UseGuards
(
new
AuthGuard
())
@
UseGuards
(
new
AuthGuard
())
@
UsePipes
(
new
ValidationPipe
())
@
UsePipes
(
new
ValidationPipe
())
async
drawMap
(@
Param
(
'
id
'
)
id
,
@
Body
()
data
)
{
async
drawMap
(@
Param
(
'
id
'
)
id
,
@
Body
()
data
:
ReturnDrawingsDTO
)
{
return
this
.
drawService
.
drawMap
(
id
,
data
);
return
this
.
drawService
.
drawMap
(
id
,
data
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/draw/draw.service.ts
+
17
−
10
View file @
7b38a20d
...
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
...
@@ -3,6 +3,7 @@ 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
'
;
@
Injectable
()
@
Injectable
()
export
class
DrawService
{
export
class
DrawService
{
...
@@ -11,11 +12,9 @@ export class DrawService {
...
@@ -11,11 +12,9 @@ export class DrawService {
private
mapDrawingRepository
:
Repository
<
MapDrawingEntity
>
,
private
mapDrawingRepository
:
Repository
<
MapDrawingEntity
>
,
)
{}
)
{}
async
draw
(
gameId
,
data
:
MapDrawing
Entity
)
{
async
draw
(
gameId
,
data
:
MapDrawing
DTO
)
{
data
[
'
gameId
'
]
=
gameId
;
data
[
'
gameId
'
]
=
gameId
;
const
drawing
=
await
this
.
mapDrawingRepository
.
create
(
data
);
const
drawing
=
await
this
.
mapDrawingRepository
.
create
(
data
);
if
(
data
.
mapDrawingId
==
null
||
data
.
mapDrawingId
==
''
)
{
if
(
data
.
mapDrawingId
==
null
||
data
.
mapDrawingId
==
''
)
{
// luo uuden instanssin.
// luo uuden instanssin.
const
mapDrawing
=
await
this
.
mapDrawingRepository
.
insert
(
drawing
);
const
mapDrawing
=
await
this
.
mapDrawingRepository
.
insert
(
drawing
);
...
@@ -27,13 +26,21 @@ export class DrawService {
...
@@ -27,13 +26,21 @@ export class DrawService {
}
}
// draw map based on game and
// draw map based on game and
async
drawMap
(
id
,
data
:
MapDrawingEntity
)
{
async
drawMap
(
id
,
data
:
ReturnDrawingsDTO
)
{
data
[
'
gameId
'
]
=
id
;
data
[
'
drawingIsActive
'
]
=
true
;
// get faction
const
mapDrawings
=
await
this
.
mapDrawingRepository
.
create
(
data
);
// return mapdrawings with given faction and gameid
// return mapdrawings with given faction and gameid
return
await
this
.
mapDrawingRepository
.
find
(
mapDrawings
);
return
await
this
.
mapDrawingRepository
.
find
({
where
:
[
{
gameId
:
id
,
faction
:
data
.
factionId
,
drawingIsActive
:
true
,
},
{
gameId
:
id
,
faction
:
null
,
drawingIsActive
:
true
,
},
],
});
}
}
}
}
This diff is collapsed.
Click to expand it.
src/draw/mapdrawing.dto.ts
+
17
−
16
View file @
7b38a20d
import
{
IsUUID
}
from
'
class-validator
'
;
import
{
IsUUID
,
IsOptional
,
IsBoolean
,
Allow
}
from
'
class-validator
'
;
import
{
GameDTO
}
from
'
../game/game.dto
'
;
import
{
GameEntity
,
Game_PersonEntity
}
from
'
../game/game.entity
'
;
import
{
FactionEntity
}
from
'
../faction/faction.entity
'
;
import
{
FactionEntity
}
from
'
../faction/faction.entity
'
;
import
{
FactionDTO
}
from
'
../faction/faction.dto
'
;
import
{
GameEntity
}
from
'
src/game/game.entity
'
;
import
{
MapDrawingEntity
}
from
'
../draw/coordinate.entity
'
;
export
class
MapDrawingDTO
{
export
class
MapDrawingDTO
{
@
IsOptional
()
@
IsUUID
(
'
4
'
)
mapDrawingId
:
string
;
@
Allow
()
data
:
JSON
;
data
:
JSON
;
gameId
:
GameDTO
;
@
IsOptional
()
faction
?:
FactionDTO
;
@
IsUUID
(
'
4
'
)
isActive
?:
boolean
;
gameId
:
GameEntity
;
validUntil
?:
string
;
@
IsOptional
()
@
IsUUID
(
'
4
'
)
faction
?:
FactionEntity
;
@
IsBoolean
()
drawingIsActive
?:
boolean
;
drawingValidTill
?:
string
;
}
}
export
class
DrawMapDTO
{
export
class
ReturnDrawingsDTO
{
@
IsOptional
()
@
IsUUID
(
'
4
'
)
@
IsUUID
(
'
4
'
)
mapDrawingId
:
MapDrawingEntity
;
gameId
:
GameEntity
;
factionId
:
FactionEntity
;
factionId
:
FactionEntity
;
gamepersonId
:
Game_PersonEntity
;
data
:
JSON
;
}
}
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