|
|
|
@ -174,9 +174,9 @@ export async function modifyAlbum(userId: number, albumId: number, album: Album, |
|
|
|
|
const artistIdsPromise: Promise<number[] | undefined> = |
|
|
|
|
album.artistIds ? |
|
|
|
|
trx.select('artistId') |
|
|
|
|
.from('artists_albums') |
|
|
|
|
.whereIn('artistId', album.artistIds) |
|
|
|
|
.then((as: any) => as.map((a: any) => a['artistId'])) |
|
|
|
|
.from('artists') |
|
|
|
|
.whereIn('id', album.artistIds) |
|
|
|
|
.then((as: any) => as.map((a: any) => a['id'])) |
|
|
|
|
: (async () => undefined)(); |
|
|
|
|
|
|
|
|
|
// Start retrieving tracks if we are modifying those.
|
|
|
|
@ -192,18 +192,18 @@ export async function modifyAlbum(userId: number, albumId: number, album: Album, |
|
|
|
|
const tagIdsPromise = |
|
|
|
|
album.tagIds ? |
|
|
|
|
trx.select('id') |
|
|
|
|
.from('albums_tags') |
|
|
|
|
.whereIn('tagId', album.tagIds) |
|
|
|
|
.then((ts: any) => ts.map((t: any) => t['tagId'])) : |
|
|
|
|
.from('tags') |
|
|
|
|
.whereIn('id', album.tagIds) |
|
|
|
|
.then((ts: any) => ts.map((t: any) => t['id'])) : |
|
|
|
|
(async () => undefined)(); |
|
|
|
|
|
|
|
|
|
// Wait for the requests to finish.
|
|
|
|
|
var [oldAlbum, artists, tags, tracks] = await Promise.all([albumIdPromise, artistIdsPromise, tagIdsPromise, trackIdsPromise]);; |
|
|
|
|
|
|
|
|
|
// Check that we found all objects we need.
|
|
|
|
|
if ((!artists || !_.isEqual(artists.sort(), (album.artistIds || []).sort())) || |
|
|
|
|
(!tags || !_.isEqual(tags.sort(), (album.tagIds || []).sort())) || |
|
|
|
|
(!tracks || !_.isEqual(tracks.sort(), (album.trackIds || []).sort())) || |
|
|
|
|
if ((album.artistIds && (!artists || !_.isEqual(artists.sort(), (album.artistIds || []).sort()))) || |
|
|
|
|
(album.tagIds && (!tags || !_.isEqual(tags.sort(), (album.tagIds || []).sort()))) || |
|
|
|
|
(album.trackIds && (!tracks || !_.isEqual(tracks.sort(), (album.trackIds || []).sort()))) || |
|
|
|
|
!oldAlbum) { |
|
|
|
|
throw makeNotFoundError(); |
|
|
|
|
} |
|
|
|
|