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); }); }