Commit 5ed90227 authored by Цой Данил's avatar Цой Данил 💬

#3 added checker to get albums by artistId/albumId or all albums

parent 2db551d4
...@@ -9,9 +9,14 @@ export class AlbumsService { ...@@ -9,9 +9,14 @@ export class AlbumsService {
public getAlbums = async(req: Request): Promise<IResponse<IAlbum[] | null>> => { public getAlbums = async(req: Request): Promise<IResponse<IAlbum[] | null>> => {
try { try {
const data = req.query.artist ? let data
await Album.find({artist: req.query.artist}).populate('artist') : if (req.query.artist){
await Album.find().populate('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{
data = await Album.find().populate('artist')
}
const response: IResponse<IAlbum[]> = { const response: IResponse<IAlbum[]> = {
status: EStatuses.SUCCESS, status: EStatuses.SUCCESS,
result: data, result: data,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment