Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw87AlenBolatov
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
Болатов Ален
hw87AlenBolatov
Commits
6342cb0f
Commit
6342cb0f
authored
Mar 30, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added getAll func in track history service
parent
88ce6589
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
1 deletion
+32
-1
7c78f2df2d68990503f20fd7a30029d1
backend/public/uploads/7c78f2df2d68990503f20fd7a30029d1
+0
-0
track.history.ts
backend/src/controllers/track.history.ts
+12
-0
artist.ts
backend/src/routes/artist.ts
+1
-1
track.history.ts
backend/src/routes/track.history.ts
+1
-0
track.history.ts
backend/src/services/track.history.ts
+18
-0
No files found.
backend/public/uploads/7c78f2df2d68990503f20fd7a30029d1
0 → 100644
View file @
6342cb0f
File added
backend/src/controllers/track.history.ts
View file @
6342cb0f
...
@@ -37,3 +37,15 @@ export const authorize = async (req: Request, res: Response) => {
...
@@ -37,3 +37,15 @@ export const authorize = async (req: Request, res: Response) => {
return
res
.
status
(
500
).
send
(
getErrorMessage
(
error
));
return
res
.
status
(
500
).
send
(
getErrorMessage
(
error
));
}
}
};
};
export
const
getTracks
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
bearedHeader
=
req
.
headers
[
'authorization'
];
const
bearer
=
bearedHeader
!
.
split
(
' '
);
const
token
=
bearer
[
1
];
const
response
=
await
TrackHistoryService
.
getAll
(
token
);
return
res
.
send
(
response
);
}
catch
(
err
)
{
return
res
.
status
(
500
).
send
(
getErrorMessage
(
err
));
}
};
backend/src/routes/artist.ts
View file @
6342cb0f
...
@@ -2,7 +2,7 @@ import expres, {Router} from 'express';
...
@@ -2,7 +2,7 @@ import expres, {Router} from 'express';
import
multer
from
'multer'
;
import
multer
from
'multer'
;
import
{
ArtistController
}
from
'../controllers/artist'
;
import
{
ArtistController
}
from
'../controllers/artist'
;
const
upload
=
multer
({
dest
:
'uploads'
});
const
upload
=
multer
({
dest
:
'
public/
uploads'
});
const
router
:
Router
=
expres
.
Router
();
const
router
:
Router
=
expres
.
Router
();
router
.
get
(
'/'
,
ArtistController
.
getArtists
);
router
.
get
(
'/'
,
ArtistController
.
getArtists
);
...
...
backend/src/routes/track.history.ts
View file @
6342cb0f
...
@@ -5,5 +5,6 @@ import {auth} from '../middleware/auth';
...
@@ -5,5 +5,6 @@ import {auth} from '../middleware/auth';
const
router
:
Router
=
Router
();
const
router
:
Router
=
Router
();
router
.
post
(
'/'
,
auth
,
TrackHistoryController
.
authorize
);
router
.
post
(
'/'
,
auth
,
TrackHistoryController
.
authorize
);
router
.
get
(
'/'
,
TrackHistoryController
.
getTracks
);
export
{
router
as
TrackHistoryRouter
};
export
{
router
as
TrackHistoryRouter
};
backend/src/services/track.history.ts
View file @
6342cb0f
import
ITrackHistory
from
'../interfaces/ITrackHistory'
;
import
ITrackHistory
from
'../interfaces/ITrackHistory'
;
import
TrackHistoryModel
from
'../models/track.history'
;
import
TrackHistoryModel
from
'../models/track.history'
;
import
UserModel
from
'../models/user'
;
export
async
function
create
(
trackHistory
:
ITrackHistory
)
{
export
async
function
create
(
trackHistory
:
ITrackHistory
)
{
try
{
try
{
...
@@ -12,3 +13,20 @@ export async function create(trackHistory: ITrackHistory) {
...
@@ -12,3 +13,20 @@ export async function create(trackHistory: ITrackHistory) {
throw
error
;
throw
error
;
}
}
}
}
export
async
function
getAll
(
token
:
string
)
{
try
{
const
userId
=
await
UserModel
.
findOne
({
token
});
const
trackHistories
=
await
TrackHistoryModel
.
find
({
user
:
userId
,
})
.
populate
({
path
:
'track'
,
populate
:
{
path
:
'album'
,
populate
:
{
path
:
'artist'
}},
})
.
sort
({
datetime
:
-
1
});
return
trackHistories
;
}
catch
(
error
)
{
throw
error
;
}
}
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