const models = require('../models'); import * as api from '../../client/src/api'; import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types'; export const CreateArtistEndpointHandler: EndpointHandler = async (req: any, res: any) => { if (!api.checkCreateArtistRequest(req)) { const e: EndpointError = { internalMessage: 'Invalid CreateArtist request: ' + JSON.stringify(req.body), httpStatus: 400 }; throw e; } const reqObject: api.CreateArtistRequest = req.body; await models.Artist.create(reqObject) .then((artist: any) => { const responseObject: api.CreateArtistResponse = { id: artist.id }; res.status(200).send(responseObject); }) .catch(catchUnhandledErrors); }