const models = require('../models'); import * as api from '../../client/src/api'; import { EndpointError, EndpointHandler } from './types'; export const ListArtistsEndpointHandler:EndpointHandler = async (req: any, res: any) => { if (!api.checkListArtistsRequest(req)) { const e:EndpointError = { internalMessage: 'Invalid ListArtists request: ' + JSON.stringify(req.body), httpStatus: 400 }; throw e; } await models.Artist.findAll() .then((artists: any[]) => { const response: api.ListArtistsResponse = artists.map((artist: any) => { return { name: artist.name, id: artist.id, }; }); res.send(response); }); }