Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
Homework_89_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_89_Tsoy_Danil
Commits
83dabed5
Commit
83dabed5
authored
Mar 22, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
#5
#6
added models and interfaces for TrackHistory
parent
cd4dc7ce
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
8 deletions
+47
-8
usersController.ts
src/controllers/usersController.ts
+1
-1
ITrackHistory.ts
src/interfaces/ITrackHistory.ts
+8
-0
ITrackHistoryDto.ts
src/interfaces/ITrackHistoryDto.ts
+7
-0
IUser.ts
src/interfaces/IUser.ts
+2
-2
TrackHistory.ts
src/models/TrackHistory.ts
+23
-0
User.ts
src/models/User.ts
+1
-1
mongooseDB.ts
src/repository/mongooseDB.ts
+4
-3
usersService.ts
src/services/usersService.ts
+1
-1
No files found.
src/controllers/usersController.ts
View file @
83dabed5
...
...
@@ -24,7 +24,7 @@ export class UsersController {
}
public
loginUser
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
:
IResponse
<
IUser
|
null
>
=
await
this
.
service
.
loginUser
(
req
.
body
)
const
response
:
IResponse
<
{
token
:
string
}
|
null
>
=
await
this
.
service
.
loginUser
(
req
.
body
)
res
.
status
(
200
).
send
(
response
)
}
}
...
...
src/interfaces/ITrackHistory.ts
View file @
83dabed5
import
ITrack
from
"./ITrack"
;
import
IUser
from
"./IUser"
;
export
default
interface
ITrackHistory
{
user
:
IUser
[
'_id'
]
track
:
ITrack
[
'_id'
]
datetime
:
Date
}
\ No newline at end of file
src/interfaces/ITrackHistoryDto.ts
0 → 100644
View file @
83dabed5
import
ITrack
from
"./ITrack"
;
import
IUser
from
"./IUser"
;
export
default
interface
ITrackHistoryDto
{
token
:
IUser
[
'token'
]
track
:
ITrack
[
'_id'
]
}
\ No newline at end of file
src/interfaces/IUser.ts
View file @
83dabed5
import
{
Document
}
from
"mongoose"
import
{
Document
,
Types
}
from
"mongoose"
export
default
interface
IUser
extends
Document
{
_id
:
string
_id
:
Types
.
ObjectId
username
:
string
password
:
string
token
:
string
...
...
src/models/TrackHistory.ts
0 → 100644
View file @
83dabed5
import
mongoose
,
{
Schema
}
from
"mongoose"
;
import
ITrackHistory
from
"../interfaces/ITrackHistory"
;
const
TrackHistorySchema
:
Schema
=
new
Schema
<
ITrackHistory
>
({
user
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'User'
,
required
:
true
},
track
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Track'
,
required
:
true
},
datetime
:{
type
:
Date
,
timestamps
:
true
}
})
export
const
TrackHistory
=
mongoose
.
model
<
ITrackHistory
>
(
'TrackHistory'
,
TrackHistorySchema
)
src/models/User.ts
View file @
83dabed5
...
...
@@ -16,7 +16,7 @@ const UserSchema: Schema = new Schema<IUser>({
},
token
:
{
type
:
String
,
required
:
tru
e
required
:
fals
e
}
},{
versionKey
:
false
})
...
...
src/repository/mongooseDB.ts
View file @
83dabed5
...
...
@@ -197,7 +197,7 @@ export class MongooseDB {
}
}
public
loginUser
=
async
(
userDto
:
IUserDto
):
Promise
<
IResponse
<
IUser
|
null
>>
=>
{
public
loginUser
=
async
(
userDto
:
IUserDto
):
Promise
<
IResponse
<
{
token
:
string
}
|
null
>>
=>
{
try
{
const
user
=
await
User
.
findOne
({
username
:
userDto
.
username
})
if
(
!
user
)
throw
new
Error
(
'User not found'
)
...
...
@@ -206,9 +206,10 @@ export class MongooseDB {
if
(
!
isMatch
)
throw
new
Error
(
'Wrong password'
)
// @ts-ignore
user
.
generateToken
()
const
response
:
IResponse
<
IUser
>
=
{
const
data
=
await
user
.
save
()
const
response
:
IResponse
<
{
token
:
string
}
>
=
{
status
:
EStatuses
.
SUCCESS
,
result
:
user
,
result
:
{
token
:
data
.
token
}
,
message
:
'Access granted'
}
return
response
...
...
src/services/usersService.ts
View file @
83dabed5
...
...
@@ -14,7 +14,7 @@ export class UsersService {
return
await
this
.
repository
.
addUser
(
userDto
)
}
public
loginUser
=
async
(
userDto
:
IUserDto
):
Promise
<
IResponse
<
IUser
|
null
>>
=>
{
public
loginUser
=
async
(
userDto
:
IUserDto
):
Promise
<
IResponse
<
{
token
:
string
}
|
null
>>
=>
{
return
await
this
.
repository
.
loginUser
(
userDto
)
}
}
...
...
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