From e068d24540cbae7041eec1fbaf51836f78fe927d Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 5 Jan 2025 11:01:25 -0500 Subject: [PATCH] fix: clearer code for finding trackgroup by urlSlug --- src/utils/trackGroup.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/utils/trackGroup.ts b/src/utils/trackGroup.ts index ee95210ba..af04f1ee7 100644 --- a/src/utils/trackGroup.ts +++ b/src/utils/trackGroup.ts @@ -94,12 +94,15 @@ export const deleteTrackGroup = async ( }; export const findTrackGroupIdForSlug = async ( - id: string, + trackGroupIdOrSlug: string, artistId?: string ) => { - let foundId: number | undefined = Number(id); + let foundtrackGroupId: number | undefined = Number(trackGroupIdOrSlug); - if (Number.isNaN(foundId) || (Number.isFinite(+foundId) && artistId)) { + if ( + Number.isNaN(foundtrackGroupId) || + (Number.isFinite(+foundtrackGroupId) && artistId) + ) { if (!artistId) { throw new Error( "Searching for a TrackGroup by slug requires an artistId" @@ -110,22 +113,22 @@ export const findTrackGroupIdForSlug = async ( if (parsedArtistId) { const trackGroup = await prisma.trackGroup.findFirst({ where: { - urlSlug: { equals: id, mode: "insensitive" }, + urlSlug: { equals: trackGroupIdOrSlug, mode: "insensitive" }, artistId: parsedArtistId, }, }); - foundId = trackGroup ? trackGroup.id : undefined; + foundtrackGroupId = trackGroup ? trackGroup.id : undefined; } else { - logger.error( - `findTrackGroupIdForSlug: returning undefined for id: ${id} artistId: ${artistId}` + logger.info( + `findTrackGroupIdForSlug: returning undefined for trackGroupId: ${trackGroupIdOrSlug}, artistId: ${artistId}` ); return undefined; } } else { - foundId = Number(id); + foundtrackGroupId = Number(trackGroupIdOrSlug); } - return foundId; + return foundtrackGroupId; }; export const trackGroupSingleInclude = (options: {