fix: scope team page scorers by teamId instead of filtering global top 200

Teams with few goals (e.g. Qatar) were missing from the sidebar because
topScorers(limit:200) only returned all-time top scorers. Now the query
filters by teamId in SQL so every team shows their own scorers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 21:11:16 +02:00
parent 9b8e266f88
commit 6e6e819718
3 changed files with 11 additions and 11 deletions
+6 -4
View File
@@ -152,11 +152,13 @@ export const resolvers = {
return found ? teamWithSlug(found) : null
} catch (e) { if (isMissingTable(e)) return null; throw e }
},
async topScorers(_: unknown, { year, limit = 20 }: { year?: number; limit?: number }) {
async topScorers(_: unknown, { year, limit = 20, teamId }: { year?: number; limit?: number; teamId?: number }) {
try {
const conditions = year
? sql`AND m.tournament_year = ${year} AND m.is_quali_playoff = false`
: sql`AND m.is_quali_playoff = false`
const conditions = sql`
${year ? sql`AND m.tournament_year = ${year}` : sql``}
${teamId ? sql`AND g.team_id = ${teamId}` : sql``}
AND m.is_quali_playoff = false
`
const rows = await db.execute(sql`
SELECT
g.player_name,
+1 -1
View File
@@ -170,7 +170,7 @@ export const typeDefs = /* GraphQL */ `
teams: [Team!]!
team(slug: String!): Team
topScorers(year: Int, limit: Int): [ScorerEntry!]!
topScorers(year: Int, limit: Int, teamId: Int): [ScorerEntry!]!
player(name: String!): ScorerEntry
hatTricks(year: Int): [HatTrick!]!