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.
 
 
 
 

34 lines
1.1 KiB

const models = require('../models');
import * as api from '../../client/src/api';
import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types';
export const ArtistDetailsEndpointHandler: EndpointHandler = async (req: any, res: any) => {
if (!api.checkArtistDetailsRequest(req)) {
const e: EndpointError = {
internalMessage: 'Invalid ArtistDetails request: ' + JSON.stringify(req.body),
httpStatus: 400
};
throw e;
}
await models.Artist.findAll({
where: {
id: req.params.id
}
})
.then((artists: any[]) => {
if (artists.length != 1) {
const e: EndpointError = {
internalMessage: 'There is no artist with id ' + req.params.id + '.',
httpStatus: 400
};
throw e;
}
let artist = artists[0];
const response: api.ArtistDetailsResponse = {
name: artist.name
};
res.send(response);
})
.catch(catchUnhandledErrors);
}