You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
const models = require('../models'); |
|
import * as api from '../../client/src/api'; |
|
import { EndpointError, EndpointHandler } from './types'; |
|
|
|
export const ListSongsEndpointHandler:EndpointHandler = async (req: any, res: any) => { |
|
if (!api.checkListSongsRequest(req)) { |
|
const e:EndpointError = { |
|
internalMessage: 'Invalid ListSongs request: ' + JSON.stringify(req.body), |
|
httpStatus: 400 |
|
}; |
|
throw e; |
|
} |
|
await models.Song.findAll({ |
|
include: [models.Artist, models.Album] |
|
}) |
|
.then((songs: any[]) => { |
|
console.log(songs); |
|
const response: api.ListSongsResponse = songs.map((song: any) => { |
|
return { |
|
title: song.title, |
|
id: song.id, |
|
artists: song.Artists.map((artist: any) => { |
|
return { |
|
name: artist.name, |
|
id: artist.id, |
|
}; |
|
}), |
|
albums: song.Albums.map((album: any) => { |
|
return { |
|
name: album.name, |
|
id: album.id, |
|
}; |
|
}), |
|
}; |
|
}); |
|
res.send(response); |
|
}); |
|
} |