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.
28 lines
955 B
28 lines
955 B
const models = require('../models'); |
|
import * as api from '../../client/src/api'; |
|
import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types'; |
|
|
|
export const QueryArtistsEndpointHandler: EndpointHandler = async (req: any, res: any) => { |
|
if (!api.checkQueryArtistsRequest(req.body)) { |
|
const e: EndpointError = { |
|
internalMessage: 'Invalid QueryArtists request: ' + JSON.stringify(req.body), |
|
httpStatus: 400 |
|
}; |
|
throw e; |
|
} |
|
const reqObject: api.QueryArtistsRequest = req.body; |
|
|
|
await models.Artist.findAll({ |
|
offset: reqObject.offset, |
|
limit: reqObject.limit, |
|
}) |
|
.then((artists: any[]) => { |
|
const response: api.QueryArtistsResponse = { |
|
ids: artists.map((artist: any) => { |
|
return artist.id |
|
}) |
|
} |
|
res.send(response); |
|
}) |
|
.catch(catchUnhandledErrors); |
|
} |