diff --git a/server/db/Album.ts b/server/db/Album.ts index ba21e14..a5c18d2 100644 --- a/server/db/Album.ts +++ b/server/db/Album.ts @@ -174,9 +174,9 @@ export async function modifyAlbum(userId: number, albumId: number, album: Album, const artistIdsPromise: Promise = 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(); }