Spaces:
Sleeping
Sleeping
Commit ·
229d06d
1
Parent(s): 1072260
bug fix 44
Browse files
src/app/api/github/events/[username]/route.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
-
import { eq } from "drizzle-orm";
|
| 12 |
|
| 13 |
interface GitHubEvent {
|
| 14 |
id: string;
|
|
@@ -36,10 +36,10 @@ export async function GET(
|
|
| 36 |
const { searchParams } = new URL(request.url);
|
| 37 |
const year = parseInt(searchParams.get('year') || String(new Date().getFullYear()));
|
| 38 |
|
| 39 |
-
// Get user's GitHub token
|
| 40 |
const user = await db.select()
|
| 41 |
.from(users)
|
| 42 |
-
.where(
|
| 43 |
.limit(1);
|
| 44 |
|
| 45 |
const githubToken = user[0]?.githubAccessToken || process.env.GITHUB_TOKEN;
|
|
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
+
import { eq, sql } from "drizzle-orm";
|
| 12 |
|
| 13 |
interface GitHubEvent {
|
| 14 |
id: string;
|
|
|
|
| 36 |
const { searchParams } = new URL(request.url);
|
| 37 |
const year = parseInt(searchParams.get('year') || String(new Date().getFullYear()));
|
| 38 |
|
| 39 |
+
// Get user's GitHub token (case-insensitive lookup)
|
| 40 |
const user = await db.select()
|
| 41 |
.from(users)
|
| 42 |
+
.where(sql`LOWER(${users.username}) = LOWER(${username})`)
|
| 43 |
.limit(1);
|
| 44 |
|
| 45 |
const githubToken = user[0]?.githubAccessToken || process.env.GITHUB_TOKEN;
|
src/app/api/profile/[username]/github-stats/route.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
-
import { eq } from "drizzle-orm";
|
| 12 |
import { fetchGitHubContributions, calculateStreakFromContributions } from "@/lib/github-contributions";
|
| 13 |
|
| 14 |
const GITHUB_API = 'https://api.github.com';
|
|
@@ -70,7 +70,7 @@ export async function GET(
|
|
| 70 |
githubAccessToken: users.githubAccessToken
|
| 71 |
})
|
| 72 |
.from(users)
|
| 73 |
-
.where(
|
| 74 |
.limit(1);
|
| 75 |
|
| 76 |
const userToken = userRecord[0]?.githubAccessToken;
|
|
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
+
import { eq, sql } from "drizzle-orm";
|
| 12 |
import { fetchGitHubContributions, calculateStreakFromContributions } from "@/lib/github-contributions";
|
| 13 |
|
| 14 |
const GITHUB_API = 'https://api.github.com';
|
|
|
|
| 70 |
githubAccessToken: users.githubAccessToken
|
| 71 |
})
|
| 72 |
.from(users)
|
| 73 |
+
.where(sql`LOWER(${users.username}) = LOWER(${username})`)
|
| 74 |
.limit(1);
|
| 75 |
|
| 76 |
const userToken = userRecord[0]?.githubAccessToken;
|
src/app/api/profile/[username]/repos/route.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
-
import { eq } from "drizzle-orm";
|
| 12 |
import { createGitHubClient, fetchAllUserRepositories } from "@/lib/github-client";
|
| 13 |
|
| 14 |
export async function GET(
|
|
@@ -18,8 +18,8 @@ export async function GET(
|
|
| 18 |
try {
|
| 19 |
const { username } = await context.params;
|
| 20 |
|
| 21 |
-
// Find user to get their GitHub token
|
| 22 |
-
const user = await db.select().from(users).where(
|
| 23 |
|
| 24 |
if (!user[0]) {
|
| 25 |
return NextResponse.json({ repos: [] });
|
|
|
|
| 8 |
import { NextRequest, NextResponse } from "next/server";
|
| 9 |
import { db } from "@/db";
|
| 10 |
import { users } from "@/db/schema";
|
| 11 |
+
import { eq, sql } from "drizzle-orm";
|
| 12 |
import { createGitHubClient, fetchAllUserRepositories } from "@/lib/github-client";
|
| 13 |
|
| 14 |
export async function GET(
|
|
|
|
| 18 |
try {
|
| 19 |
const { username } = await context.params;
|
| 20 |
|
| 21 |
+
// Find user to get their GitHub token (case-insensitive)
|
| 22 |
+
const user = await db.select().from(users).where(sql`LOWER(${users.username}) = LOWER(${username})`).limit(1);
|
| 23 |
|
| 24 |
if (!user[0]) {
|
| 25 |
return NextResponse.json({ repos: [] });
|
src/lib/db/queries/gamification.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { streakCache, calendarCache } from "@/lib/cache";
|
|
| 12 |
// =============================================================================
|
| 13 |
|
| 14 |
export async function getUserBadges(username: string) {
|
| 15 |
-
|
|
|
|
| 16 |
if (!user[0]) return [];
|
| 17 |
|
| 18 |
return db.select()
|
|
@@ -34,7 +35,7 @@ export async function getUserStreak(username: string) {
|
|
| 34 |
return cached;
|
| 35 |
}
|
| 36 |
|
| 37 |
-
const user = await db.select().from(users).where(
|
| 38 |
if (!user[0]) {
|
| 39 |
const emptyResult = { current_streak: 0, longest_streak: 0, is_active: false, total_contribution_days: 0 };
|
| 40 |
streakCache.set(cacheKey, emptyResult);
|
|
@@ -153,7 +154,8 @@ function calculateLongestStreak(sortedDates: string[]): number {
|
|
| 153 |
// =============================================================================
|
| 154 |
|
| 155 |
export async function getUserCalendar(username: string, days: number = 365) {
|
| 156 |
-
|
|
|
|
| 157 |
if (!user[0]) return [];
|
| 158 |
|
| 159 |
// Calculate date range
|
|
|
|
| 12 |
// =============================================================================
|
| 13 |
|
| 14 |
export async function getUserBadges(username: string) {
|
| 15 |
+
// Case-insensitive lookup - GitHub usernames are case-insensitive
|
| 16 |
+
const user = await db.select().from(users).where(sql`LOWER(${users.username}) = LOWER(${username})`).limit(1);
|
| 17 |
if (!user[0]) return [];
|
| 18 |
|
| 19 |
return db.select()
|
|
|
|
| 35 |
return cached;
|
| 36 |
}
|
| 37 |
|
| 38 |
+
const user = await db.select().from(users).where(sql`LOWER(${users.username}) = LOWER(${username})`).limit(1);
|
| 39 |
if (!user[0]) {
|
| 40 |
const emptyResult = { current_streak: 0, longest_streak: 0, is_active: false, total_contribution_days: 0 };
|
| 41 |
streakCache.set(cacheKey, emptyResult);
|
|
|
|
| 154 |
// =============================================================================
|
| 155 |
|
| 156 |
export async function getUserCalendar(username: string, days: number = 365) {
|
| 157 |
+
// Case-insensitive lookup
|
| 158 |
+
const user = await db.select().from(users).where(sql`LOWER(${users.username}) = LOWER(${username})`).limit(1);
|
| 159 |
if (!user[0]) return [];
|
| 160 |
|
| 161 |
// Calculate date range
|
src/lib/db/queries/users.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
| 6 |
|
| 7 |
import { db } from "@/db";
|
| 8 |
import { users, profiles, profileSkills, profileMentoringTopics, profileConnectedRepos, userRepositories } from "@/db/schema";
|
| 9 |
-
import { eq, and, like, desc } from "drizzle-orm";
|
| 10 |
import { v4 as uuidv4 } from "uuid";
|
| 11 |
|
| 12 |
// =============================================================================
|
|
@@ -24,7 +24,8 @@ export async function getUserByGithubId(githubId: number) {
|
|
| 24 |
}
|
| 25 |
|
| 26 |
export async function getUserByUsername(username: string) {
|
| 27 |
-
|
|
|
|
| 28 |
return result[0] || null;
|
| 29 |
}
|
| 30 |
|
|
@@ -90,7 +91,8 @@ export async function getProfile(userId: string) {
|
|
| 90 |
}
|
| 91 |
|
| 92 |
export async function getProfileByUsername(username: string) {
|
| 93 |
-
|
|
|
|
| 94 |
if (!profile[0]) return null;
|
| 95 |
|
| 96 |
const userId = profile[0].userId;
|
|
|
|
| 6 |
|
| 7 |
import { db } from "@/db";
|
| 8 |
import { users, profiles, profileSkills, profileMentoringTopics, profileConnectedRepos, userRepositories } from "@/db/schema";
|
| 9 |
+
import { eq, and, like, desc, sql } from "drizzle-orm";
|
| 10 |
import { v4 as uuidv4 } from "uuid";
|
| 11 |
|
| 12 |
// =============================================================================
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
export async function getUserByUsername(username: string) {
|
| 27 |
+
// Case-insensitive lookup - GitHub usernames are case-insensitive
|
| 28 |
+
const result = await db.select().from(users).where(sql`LOWER(${users.username}) = LOWER(${username})`).limit(1);
|
| 29 |
return result[0] || null;
|
| 30 |
}
|
| 31 |
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
export async function getProfileByUsername(username: string) {
|
| 94 |
+
// Case-insensitive lookup - GitHub usernames are case-insensitive
|
| 95 |
+
const profile = await db.select().from(profiles).where(sql`LOWER(${profiles.username}) = LOWER(${username})`).limit(1);
|
| 96 |
if (!profile[0]) return null;
|
| 97 |
|
| 98 |
const userId = profile[0].userId;
|