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
4832b42d
Commit
4832b42d
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
login now returns json on error
parent
bd1b83d2
No related branches found
No related tags found
2 merge requests
!59
Development to master
,
!21
Error handling
Pipeline
#63952
passed
5 years ago
Stage: purge
Stage: e2e-test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/user/user.service.ts
+10
-13
10 additions, 13 deletions
src/user/user.service.ts
with
10 additions
and
13 deletions
src/user/user.service.ts
+
10
−
13
View file @
4832b42d
...
@@ -10,15 +10,15 @@ import { GameDTO } from '../game/game.dto';
...
@@ -10,15 +10,15 @@ import { GameDTO } from '../game/game.dto';
@
Injectable
()
@
Injectable
()
export
class
UserService
{
export
class
UserService
{
constructor
(
constructor
(
@
InjectRepository
(
PersonEntity
)
@
InjectRepository
(
PersonEntity
)
private
userRepository
:
Repository
<
PersonEntity
>
,
private
userRepository
:
Repository
<
PersonEntity
>
,
@
InjectRepository
(
GameEntity
)
@
InjectRepository
(
GameEntity
)
private
gameRepository
:
Repository
<
GameEntity
>
private
gameRepository
:
Repository
<
GameEntity
>
)
{
}
)
{
}
async
register
(
data
:
UserDTO
)
{
async
register
(
data
:
UserDTO
)
{
const
{
name
}
=
data
;
const
{
name
}
=
data
;
let
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
let
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
user
)
{
if
(
user
)
{
throw
new
HttpException
(
'
User already exists
'
,
HttpStatus
.
BAD_REQUEST
);
throw
new
HttpException
(
'
User already exists
'
,
HttpStatus
.
BAD_REQUEST
);
}
}
...
@@ -28,23 +28,20 @@ export class UserService {
...
@@ -28,23 +28,20 @@ export class UserService {
}
}
async
login
(
data
:
UserDTO
)
{
async
login
(
data
:
UserDTO
)
{
try
{
try
{
const
{
name
,
password
}
=
data
;
const
{
name
,
password
}
=
data
;
const
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}});
const
user
=
await
this
.
userRepository
.
findOne
({
where
:
{
name
}
});
if
(
!
user
||
!
(
await
user
.
comparePassword
(
password
)))
{
if
(
!
user
||
!
(
await
user
.
comparePassword
(
password
)))
{
throw
new
HttpException
(
throw
new
HttpException
(
'
invalid password
'
,
HttpStatus
.
BAD_REQUEST
);
'
Invalid username/password
'
,
HttpStatus
.
BAD_REQUEST
,
);
}
}
return
user
.
tokenObject
();
return
user
.
tokenObject
();
}
catch
(
error
){
}
catch
(
error
)
{
return
error
.
message
;
throw
new
HttpException
(
error
.
message
,
HttpStatus
.
BAD_REQUEST
)
;
}
}
}
}
// liitytään peliin
// liitytään peliin
async
joinGame
(
game
:
GameDTO
,
data
:
UserDTO
){
async
joinGame
(
game
:
GameDTO
,
data
:
UserDTO
)
{
try
{
try
{
// etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
// etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
const
role
=
await
this
.
gameRepository
.
findOne
();
const
role
=
await
this
.
gameRepository
.
findOne
();
...
@@ -55,7 +52,7 @@ export class UserService {
...
@@ -55,7 +52,7 @@ export class UserService {
}
}
// liitytään factionii
// liitytään factionii
async
joinFaction
(
game
:
GameDTO
,
data
:
UserDTO
):
Promise
<
boolean
>
{
async
joinFaction
(
game
:
GameDTO
,
data
:
UserDTO
):
Promise
<
boolean
>
{
try
{
try
{
// tarkistetaan factionin salasana
// tarkistetaan factionin salasana
return
true
;
return
true
;
...
...
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