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.
 
 
 
 

40 lines
1.3 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;
}
try {
const artists: any[] = await models.Artist.findAll({
where: {
id: req.params.id
},
include: [models.Tag]
});
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 storeLinks = Array.isArray(artist.storeLinks) ? artist.storeLinks :
(artist.storeLinks ? [artist.storeLinks] : []);
const response: api.ArtistDetailsResponse = {
name: artist.name,
tagIds: artist.Tags.map((tag: any) => tag.id),
storeLinks: storeLinks,
};
await res.send(response);
} catch (e) {
catchUnhandledErrors(e)
}
}