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.
35 lines
1.2 KiB
35 lines
1.2 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: req.params.id } |
|
}) |
|
.then(async (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]; |
|
artist.name = reqObject.name; |
|
if(reqObject.storeLinks) { artist.setStoreLinks(reqObject.storeLinks) }; |
|
await artist.save(); |
|
}) |
|
.then(() => { |
|
res.status(200).send({}); |
|
}) |
|
.catch(catchUnhandledErrors); |
|
} |