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 {
public getAlbums = async(req: Request): Promise<IResponse<IAlbum[] | null>> => {
try {
const data = req.query.artist ?
await Album.find({artist: req.query.artist}).populate('artist') :
await Album.find().populate('artist')
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{
data = await Album.find().populate('artist')
}
const response: IResponse<IAlbum[]> = {
status: EStatuses.SUCCESS,
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