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
da879f5b
Commit
da879f5b
authored
Mar 15, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#2
added method to find by artist id. Planning to connect both gets together
parent
8e96069a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
albumsController.ts
src/controllers/albumsController.ts
+1
-1
albumsService.ts
src/services/albumsService.ts
+20
-0
No files found.
src/controllers/albumsController.ts
View file @
da879f5b
...
@@ -32,7 +32,7 @@ export class AlbumsController {
...
@@ -32,7 +32,7 @@ export class AlbumsController {
}
}
private
getAlbums
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
private
getAlbums
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
=
await
this
.
service
.
getAlbums
()
const
response
=
req
.
query
.
artist
?
await
this
.
service
.
getAlbumsByArtistId
(
req
.
query
.
artist
.
toString
())
:
await
this
.
service
.
getAlbums
()
if
(
response
.
status
===
EStatuses
.
FAILURE
){
if
(
response
.
status
===
EStatuses
.
FAILURE
){
res
.
status
(
418
).
send
(
response
)
res
.
status
(
418
).
send
(
response
)
}
else
{
}
else
{
...
...
src/services/albumsService.ts
View file @
da879f5b
...
@@ -26,6 +26,26 @@ export class AlbumsService {
...
@@ -26,6 +26,26 @@ export class AlbumsService {
}
}
}
}
public
getAlbumsByArtistId
=
async
(
artistId
:
string
):
Promise
<
IResponse
<
IAlbum
[]
|
null
>>
=>
{
try
{
const
data
=
await
Album
.
find
({
artist
:
artistId
}).
populate
(
'artist'
)
const
response
:
IResponse
<
IAlbum
[]
|
null
>
=
{
status
:
EStatuses
.
SUCCESS
,
result
:
data
,
message
:
'Album found'
}
return
response
}
catch
(
err
:
unknown
){
const
error
=
err
as
Error
const
response
:
IResponse
<
null
>
=
{
status
:
EStatuses
.
FAILURE
,
result
:
null
,
message
:
error
.
message
}
return
response
}
}
public
addAlbum
=
async
(
albumDto
:
IAlbumDto
):
Promise
<
IResponse
<
IAlbum
|
null
>>
=>
{
public
addAlbum
=
async
(
albumDto
:
IAlbumDto
):
Promise
<
IResponse
<
IAlbum
|
null
>>
=>
{
try
{
try
{
if
(
albumDto
.
title
.
trim
()
===
''
||
!
albumDto
.
artist
||
!
albumDto
.
releaseYear
||
!
albumDto
.
coverImage
)
throw
new
Error
(
'All fields should exist'
)
if
(
albumDto
.
title
.
trim
()
===
''
||
!
albumDto
.
artist
||
!
albumDto
.
releaseYear
||
!
albumDto
.
coverImage
)
throw
new
Error
(
'All fields should exist'
)
...
...
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