Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/backend/src/routes/artists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
'/api/artists/suggestions',
apiLimiter,
requireAuth,
async (req: AuthenticatedRequest, res: Response) => {

Check warning on line 160 in packages/backend/src/routes/artists.ts

View workflow job for this annotation

GitHub Actions / Quality Gates

Async arrow function has a complexity of 43. Maximum allowed is 15
try {
const discordUserId = req.user?.id
if (!discordUserId) {
Expand All @@ -178,6 +178,31 @@

const suggestions = new Map<string, SpotifyArtist>()

// PRIORITY 1: user's saved preferred artists (Musical Taste page).
// These come first in Discover so the user always sees what they
// explicitly favorited before any algorithmic suggestion.
try {
const db = getPrismaClient()
const preferred = await db.userArtistPreference.findMany({
where: { discordUserId, preference: 'prefer' },
orderBy: { createdAt: 'desc' },
})
for (const pref of preferred) {
if (suggestions.size >= MAX_SUGGESTIONS) break
const id = pref.spotifyId ?? `pref:${pref.artistKey}`
if (suggestions.has(id)) continue
suggestions.set(id, {
id,
name: pref.artistName,
imageUrl: pref.imageUrl,
popularity: 0,
genres: [],
})
}
} catch (error) {
errorLog({ message: 'Failed to load preferred artists for suggestions', error })
}

const link = await spotifyLinkService.getValidAccessToken(
discordUserId,
)
Expand Down Expand Up @@ -219,8 +244,8 @@
const data = (await res.json()) as {
items?: unknown[]
}
if (Array.isArray(data.items)) {

Check warning on line 247 in packages/backend/src/routes/artists.ts

View workflow job for this annotation

GitHub Actions / Quality Gates

Blocks are nested too deeply (7). Maximum allowed is 6
for (const item of data.items) {

Check warning on line 248 in packages/backend/src/routes/artists.ts

View workflow job for this annotation

GitHub Actions / Quality Gates

Blocks are nested too deeply (8). Maximum allowed is 6
const artist = item as {
id?: string
name?: string
Expand All @@ -228,7 +253,7 @@
popularity?: number
genres?: string[]
}
if (

Check warning on line 256 in packages/backend/src/routes/artists.ts

View workflow job for this annotation

GitHub Actions / Quality Gates

Blocks are nested too deeply (9). Maximum allowed is 6
artist.id &&
artist.name &&
suggestions.size < MAX_SUGGESTIONS
Expand All @@ -241,7 +266,7 @@
popularity: artist.popularity ?? 0,
genres: artist.genres ?? [],
}
if (!suggestions.has(artist.id)) {

Check warning on line 269 in packages/backend/src/routes/artists.ts

View workflow job for this annotation

GitHub Actions / Quality Gates

Blocks are nested too deeply (10). Maximum allowed is 6
collected.push(entry)
}
suggestions.set(artist.id, entry)
Expand Down