diff --git a/lib/graphql/resolvers/index.ts b/lib/graphql/resolvers/index.ts index 0dc5d0f..71d4533 100644 --- a/lib/graphql/resolvers/index.ts +++ b/lib/graphql/resolvers/index.ts @@ -120,7 +120,17 @@ export const resolvers = { isNotNull(matches.scoreFtHome), eq(matches.isQualiPlayoff, false), )) - .orderBy(desc(matches.date), desc(matches.id)) + .orderBy( + sql`CASE + WHEN ${matches.timeLocal} LIKE '% UTC%' + THEN ${matches.date}::date + + SPLIT_PART(${matches.timeLocal}, ' ', 1)::time + - (REPLACE(SPLIT_PART(${matches.timeLocal}, ' ', 2), 'UTC', '') || ' hours')::interval + ELSE ${matches.date}::date + + COALESCE(NULLIF(SPLIT_PART(${matches.timeLocal}, ' ', 1), '')::time, '00:00'::time) + END DESC NULLS LAST`, + desc(matches.id), + ) .limit(limit * 2) const hydrated = await Promise.all(rows.map(hydrateMatch)) return hydrated.filter(m => !m.isLive).slice(0, limit)