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
3eafdd7f
Commit
3eafdd7f
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
updated newTask and created editTask service
parent
d640fafc
No related branches found
No related tags found
4 merge requests
!59
Development to master
,
!31
Development
,
!25
Dto service
,
!24
Faction task edit
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/task/task.service.ts
+40
-2
40 additions, 2 deletions
src/task/task.service.ts
with
40 additions
and
2 deletions
src/task/task.service.ts
+
40
−
2
View file @
3eafdd7f
...
...
@@ -2,20 +2,58 @@ import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import
{
Repository
}
from
'
typeorm
'
;
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
TaskEntity
}
from
'
./task.entity
'
;
import
{
TaskDTO
}
from
'
./task.dto
'
;
import
{
CreateTaskDTO
,
EditTaskDTO
}
from
'
./task.dto
'
;
import
{
FactionEntity
}
from
'
../game/faction.entity
'
;
@
Injectable
()
export
class
TaskService
{
constructor
(
@
InjectRepository
(
TaskEntity
)
private
taskRepository
:
Repository
<
TaskEntity
>
,
@
InjectRepository
(
FactionEntity
)
private
factionRepository
:
Repository
<
FactionEntity
>
,
)
{}
async
newTask
(
task
:
TaskDTO
)
{
async
newTask
(
task
:
CreateTaskDTO
)
{
// check if is not null, check that the faction exists in the game
if
(
task
.
faction
!=
null
&&
!
(
await
this
.
factionRepository
.
findOne
({
factionId
:
task
.
faction
.
toString
(),
game
:
task
.
taskGame
,
}))
)
{
throw
new
HttpException
(
'
Faction not found
'
,
HttpStatus
.
BAD_REQUEST
);
}
const
createdTask
=
await
this
.
taskRepository
.
create
(
task
);
console
.
log
(
createdTask
);
await
this
.
taskRepository
.
insert
(
createdTask
);
return
{
message
:
'
Task added
'
,
};
}
async
editTask
(
data
:
EditTaskDTO
)
{
const
task
=
await
this
.
taskRepository
.
findOne
(
data
.
taskId
);
console
.
log
(
task
);
// checks if task is already closed
if
(
!
task
.
taskIsActive
)
{
throw
new
HttpException
(
'
Task is not active
'
,
HttpStatus
.
BAD_REQUEST
);
}
// checks if faction is valid
if
(
!
(
await
this
.
factionRepository
.
findOne
({
factionId
:
data
.
taskWinner
.
toString
(),
game
:
data
.
taskGame
,
}))
)
{
throw
new
HttpException
(
'
Faction not found
'
,
HttpStatus
.
BAD_REQUEST
);
}
task
.
taskWinner
=
data
.
taskWinner
;
task
.
taskIsActive
=
false
;
await
this
.
taskRepository
.
save
(
task
);
return
{
message
:
'
Task updated and closed
'
,
};
}
}
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