Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
initial_project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нұрасыл Қайратұлы
initial_project
Commits
fffd782f
Commit
fffd782f
authored
Aug 13, 2024
by
Нұрасыл Қайратұлы
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
718404e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
user.controller.ts
server/src/controllers/user.controller.ts
+17
-5
user.service.ts
server/src/services/user.service.ts
+5
-0
No files found.
server/src/controllers/user.controller.ts
View file @
fffd782f
import
{
UserService
}
from
"@/services/user.service"
;
import
{
RequestHandler
}
from
"express"
;
import
{
plainToInstance
}
from
'class-transformer'
;
// import { SignInUserDto } from "@/dto/sign-in-user.dto";
import
{
RegistrationUserDto
}
from
"@/dto/registration-user.dto"
;
import
{
SignInUserDto
}
from
"@/dto/sign-in-user.dto"
;
import
{
formatErrors
}
from
"@/helpers/formatErrors"
;
export
class
UserController
{
private
service
:
UserService
;
...
...
@@ -18,14 +18,26 @@ export class UserController {
const
user
=
await
this
.
service
.
signIn
(
signInDto
)
res
.
send
(
user
)
}
catch
(
e
)
{
res
.
status
(
401
).
send
((
e
as
Error
).
message
)
if
(
Array
.
isArray
(
e
))
{
res
.
status
(
400
).
send
(
formatErrors
(
e
));
}
else
{
res
.
status
(
500
).
send
(
e
);
}
}
}
registration
:
RequestHandler
=
async
(
req
,
res
):
Promise
<
void
>
=>
{
const
registrationInDto
=
plainToInstance
(
RegistrationUserDto
,
req
.
body
)
const
user
=
await
this
.
service
.
registration
(
registrationInDto
)
res
.
send
(
user
)
try
{
const
registrationInDto
=
plainToInstance
(
RegistrationUserDto
,
req
.
body
)
const
user
=
await
this
.
service
.
registration
(
registrationInDto
)
res
.
send
(
user
)
}
catch
(
e
)
{
if
(
Array
.
isArray
(
e
))
{
res
.
status
(
400
).
send
(
formatErrors
(
e
));
}
else
{
res
.
status
(
500
).
send
(
e
);
}
}
}
validateToken
:
RequestHandler
=
async
(
req
,
res
):
Promise
<
void
>
=>
{
...
...
server/src/services/user.service.ts
View file @
fffd782f
import
{
SignInUserDto
}
from
"@/dto/sign-in-user.dto"
import
{
RegistrationUserDto
}
from
"@/dto/registration-user.dto"
import
{
userRepo
}
from
"@/repositories/user.repository"
import
{
validate
}
from
"class-validator"
export
class
UserService
{
async
signIn
(
signInUserDto
:
SignInUserDto
)
{
const
errors
=
await
validate
(
signInUserDto
,
{
whitelist
:
true
})
if
(
errors
.
length
)
throw
errors
return
await
userRepo
.
signIn
(
signInUserDto
)
}
async
registration
(
registrationUserDto
:
RegistrationUserDto
)
{
const
errors
=
await
validate
(
registrationUserDto
,
{
whitelist
:
true
})
if
(
errors
.
length
)
throw
errors
return
await
userRepo
.
registration
(
registrationUserDto
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment