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 ModifyArtistEndpointHandler: EndpointHandler = async (req: any, res: any) => {
if (!api.checkModifyArtistRequest(req)) {
const e: EndpointError = {
internalMessage: 'Invalid ModifyArtist request: ' + JSON.stringify(req.body),
httpStatus: 400
};
throw e;
}
const reqObject: api.ModifyArtistRequest = req.body;
await models.Artist.findAll({
where: { id: reqObject.id }
})
.then(async (artists: any[]) => {
if (artists.length != 1) {
const e: EndpointError = {
internalMessage: 'There is no artist with id ' + reqObject.id + '.',
httpStatus: 400
};
throw e;
}
let artist = artists[0];
artist.name = reqObject.name;
await artist.save();
})
.then(() => {
res.status(200);
})
.catch(catchUnhandledErrors);
}