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.
 
 
 
 

31 lines
1.1 KiB

const models = require('../models');
import * as api from '../../client/src/api';
export const ListSongsEndpointHandler = (req: any, res: any) => {
if (!api.checkListSongsRequest(req)) {
console.log('Invalid ListSongs request: ' + JSON.stringify(req.body));
res.sendStatus(400);
return;
}
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);
});
}