Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
Homework_95_Tsoy_Danil
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
Цой Данил
Homework_95_Tsoy_Danil
Commits
d52ebea0
Commit
d52ebea0
authored
Apr 11, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added all functions for user. Login, create, checktoken and etc
parent
569a1e4f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
1 deletion
+71
-1
usersController.ts
backend/src/controllers/usersController.ts
+46
-0
mongooseDB.ts
backend/src/repository/mongooseDB.ts
+3
-1
usersService.ts
backend/src/services/usersService.ts
+22
-0
No files found.
backend/src/controllers/usersController.ts
0 → 100644
View file @
d52ebea0
import
express
,
{
Request
,
Response
,
Router
}
from
"express"
import
{
EStatuses
}
from
"../enum/EStatuses"
;
import
IResponse
from
"../interfaces/IResponse"
;
import
IUser
from
"../interfaces/IUser"
;
import
IUserGetDto
from
"../interfaces/IUserGetDto"
;
import
{
auth
}
from
"../middlewares/auth"
;
import
{
usersService
,
UsersService
}
from
"../services/usersService"
;
import
IModifiedRequest
from
"../interfaces/IModifiedRequest"
;
export
class
UsersController
{
private
service
:
UsersService
private
router
:
Router
constructor
(){
this
.
service
=
usersService
this
.
router
=
express
.
Router
()
this
.
router
.
post
(
'/'
,
this
.
createUser
)
this
.
router
.
post
(
'/sessions'
,
this
.
loginUser
)
this
.
router
.
get
(
'/token'
,
auth
,
this
.
checkToken
)
}
public
getRouter
=
()
=>
{
return
this
.
router
}
private
createUser
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
:
IResponse
<
IUserGetDto
|
null
>
=
await
this
.
service
.
createUser
(
req
.
body
)
res
.
status
(
200
).
send
(
response
)
}
public
loginUser
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
:
IResponse
<
IUserGetDto
|
null
>
=
await
this
.
service
.
loginUser
(
req
.
body
)
res
.
status
(
200
).
send
(
response
)
}
public
checkToken
=
async
(
expressReq
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
req
=
expressReq
as
IModifiedRequest
const
response
:
IResponse
<
IUserGetDto
|
null
>
=
{
status
:
EStatuses
.
SUCCESS
,
result
:
req
.
verifiedData
as
IUserGetDto
,
message
:
'Token is ok'
}
res
.
status
(
200
).
send
(
response
)
}
}
export
const
usersController
=
new
UsersController
()
\ No newline at end of file
backend/src/repository/mongooseDB.ts
View file @
d52ebea0
...
...
@@ -81,4 +81,6 @@ export class MongooseDB {
return
response
}
}
}
\ No newline at end of file
}
export
const
mongooseDB
=
new
MongooseDB
()
\ No newline at end of file
backend/src/services/usersService.ts
0 → 100644
View file @
d52ebea0
import
IResponse
from
"../interfaces/IResponse"
;
import
IUser
from
"../interfaces/IUser"
;
import
IUserCreateDto
from
"../interfaces/IUserCreateDto"
;
import
IUserGetDto
from
"../interfaces/IUserGetDto"
;
import
{
mongooseDB
,
MongooseDB
}
from
"../repository/mongooseDB"
;
export
class
UsersService
{
private
repository
:
MongooseDB
constructor
(){
this
.
repository
=
mongooseDB
}
public
createUser
=
async
(
userDto
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
null
>>
=>
{
return
await
this
.
repository
.
createUser
(
userDto
)
}
public
loginUser
=
async
(
userDto
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
null
>>
=>
{
return
await
this
.
repository
.
loginUser
(
userDto
)
}
}
export
const
usersService
=
new
UsersService
()
\ No newline at end of file
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