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
55635b89
Commit
55635b89
authored
Mar 15, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3
connected all search album methods in one service method
parent
5ed90227
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
albumsController.ts
src/controllers/albumsController.ts
+3
-2
albumsService.ts
src/services/albumsService.ts
+5
-4
No files found.
src/controllers/albumsController.ts
View file @
55635b89
...
...
@@ -23,7 +23,8 @@ export class AlbumsController {
constructor
()
{
this
.
router
=
express
.
Router
()
this
.
service
=
albumsService
this
.
router
.
get
(
'/'
,
this
.
getAlbums
)
this
.
router
.
get
(
'/'
,
this
.
getAlbumsHandler
)
this
.
router
.
get
(
'/:id'
,
this
.
getAlbumsHandler
)
this
.
router
.
post
(
'/'
,
upload
.
single
(
'coverImage'
),
this
.
addAlbum
)
}
...
...
@@ -31,7 +32,7 @@ export class AlbumsController {
return
this
.
router
;
}
private
getAlbums
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
private
getAlbums
Handler
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
=
await
this
.
service
.
getAlbums
(
req
)
if
(
response
.
status
===
EStatuses
.
FAILURE
){
res
.
status
(
418
).
send
(
response
)
...
...
src/services/albumsService.ts
View file @
55635b89
...
...
@@ -7,17 +7,18 @@ import { Request } from "express";
export
class
AlbumsService
{
public
getAlbums
=
async
(
req
:
Request
):
Promise
<
IResponse
<
IAlbum
[]
|
null
>>
=>
{
public
getAlbums
=
async
(
req
:
Request
):
Promise
<
IResponse
<
IAlbum
[]
|
IAlbum
|
null
>>
=>
{
try
{
let
data
if
(
req
.
query
.
artist
){
data
=
await
Album
.
find
({
artist
:
req
.
query
.
artist
}).
populate
(
'artist'
)
}
else
if
(
req
.
query
.
album
){
data
=
await
Album
.
find
({
_id
:
req
.
query
.
album
}
).
populate
(
'artist'
)
}
else
if
(
req
.
params
.
id
){
data
=
await
Album
.
find
ById
(
req
.
params
.
id
).
populate
(
'artist'
)
}
else
{
data
=
await
Album
.
find
().
populate
(
'artist'
)
}
const
response
:
IResponse
<
IAlbum
[]
>
=
{
if
(
data
===
null
||
data
===
undefined
)
throw
new
Error
(
'No album found'
)
const
response
:
IResponse
<
IAlbum
[]
|
IAlbum
|
null
>
=
{
status
:
EStatuses
.
SUCCESS
,
result
:
data
,
message
:
'Albums found'
...
...
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