|
|
@ -180,19 +180,19 @@ export async function modifyTrack(userId: number, trackId: number, track: Track, |
|
|
|
// Start retrieving artists if we are modifying those.
|
|
|
|
// Start retrieving artists if we are modifying those.
|
|
|
|
const artistIdsPromise: Promise<number[] | undefined> = |
|
|
|
const artistIdsPromise: Promise<number[] | undefined> = |
|
|
|
track.artistIds ? |
|
|
|
track.artistIds ? |
|
|
|
trx.select('artistId') |
|
|
|
trx.select('id') |
|
|
|
.from('tracks_artists') |
|
|
|
.from('artists') |
|
|
|
.whereIn('artistId', track.artistIds) |
|
|
|
.whereIn('id', track.artistIds) |
|
|
|
.then((as: any) => as.map((a: any) => a['artistId'])) |
|
|
|
.then((as: any) => as.map((a: any) => a['id'])) |
|
|
|
: (async () => undefined)(); |
|
|
|
: (async () => undefined)(); |
|
|
|
|
|
|
|
|
|
|
|
// Start retrieving tags if we are modifying those.
|
|
|
|
// Start retrieving tags if we are modifying those.
|
|
|
|
const tagIdsPromise = |
|
|
|
const tagIdsPromise = |
|
|
|
track.tagIds ? |
|
|
|
track.tagIds ? |
|
|
|
trx.select('id') |
|
|
|
trx.select('id') |
|
|
|
.from('tracks_tags') |
|
|
|
.from('tags') |
|
|
|
.whereIn('tagId', track.tagIds) |
|
|
|
.whereIn('id', track.tagIds) |
|
|
|
.then((ts: any) => ts.map((t: any) => t['tagId'])) : |
|
|
|
.then((ts: any) => ts.map((t: any) => t['id'])) : |
|
|
|
(async () => undefined)(); |
|
|
|
(async () => undefined)(); |
|
|
|
|
|
|
|
|
|
|
|
// Start retrieving album if we are modifying that.
|
|
|
|
// Start retrieving album if we are modifying that.
|
|
|
@ -205,15 +205,15 @@ export async function modifyTrack(userId: number, trackId: number, track: Track, |
|
|
|
.then((r: any) => (r && r[0]) ? r[0]['id'] : undefined) : |
|
|
|
.then((r: any) => (r && r[0]) ? r[0]['id'] : undefined) : |
|
|
|
(async () => undefined)(); |
|
|
|
(async () => undefined)(); |
|
|
|
|
|
|
|
|
|
|
|
let blablums = await trx.select('id').from('albums'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for the requests to finish.
|
|
|
|
// Wait for the requests to finish.
|
|
|
|
var [oldTrack, artists, tags, album] = await Promise.all([trackIdPromise, artistIdsPromise, tagIdsPromise, albumIdPromise]);; |
|
|
|
var [oldTrack, artists, tags, album] = await Promise.all([trackIdPromise, artistIdsPromise, tagIdsPromise, albumIdPromise]);; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Patch track: ", oldTrack, artists, tags, album); |
|
|
|
|
|
|
|
|
|
|
|
// Check that we found all objects we need.
|
|
|
|
// Check that we found all objects we need.
|
|
|
|
if ((!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort())) || |
|
|
|
if ((track.artistIds && (!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort()))) || |
|
|
|
(!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort())) || |
|
|
|
(track.tagIds && (!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort()))) || |
|
|
|
(!album && track.albumId) || |
|
|
|
(track.albumId && !album) || |
|
|
|
!oldTrack) { |
|
|
|
!oldTrack) { |
|
|
|
throw makeNotFoundError(); |
|
|
|
throw makeNotFoundError(); |
|
|
|
} |
|
|
|
} |
|
|
|