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
40 lines
1.3 KiB
const models = require('../models'); |
|
import * as api from '../../client/src/api'; |
|
import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types'; |
|
|
|
export const AlbumDetailsEndpointHandler: EndpointHandler = async (req: any, res: any) => { |
|
if (!api.checkAlbumDetailsRequest(req)) { |
|
const e: EndpointError = { |
|
internalMessage: 'Invalid AlbumDetails request: ' + JSON.stringify(req.body), |
|
httpStatus: 400 |
|
}; |
|
throw e; |
|
} |
|
|
|
try { |
|
const albums = await models.Album.findAll({ |
|
include: [models.Artist, models.Tag, models.Song], |
|
where: { |
|
id: req.params.id |
|
} |
|
}); |
|
if (albums.length != 1) { |
|
const e: EndpointError = { |
|
internalMessage: 'There is no album with id ' + req.params.id + '.', |
|
httpStatus: 400 |
|
}; |
|
throw e; |
|
} |
|
let album = albums[0]; |
|
const response: api.AlbumDetailsResponse = { |
|
name: album.name, |
|
artistIds: album.Artists.map((artist: any) => artist.id), |
|
tagIds: album.Tags.map((tag: any) => tag.id), |
|
songIds: album.Songs.map((song: any) => song.id), |
|
storeLinks: album.storeLinks, |
|
} |
|
await res.send(response); |
|
} catch (e) { |
|
catchUnhandledErrors(e); |
|
} |
|
} |