From 019945863ea1a53c3f997e3c1d8e0c49759d6c14 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 22:05:03 +0000 Subject: [PATCH] Add profile lookup and listing helpers cgen-4559e4c1ecfe4176866c30f5af37f0c1 --- client/lib/aethex-database-adapter.ts | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/client/lib/aethex-database-adapter.ts b/client/lib/aethex-database-adapter.ts index bc68d2ab..b1b3e041 100644 --- a/client/lib/aethex-database-adapter.ts +++ b/client/lib/aethex-database-adapter.ts @@ -172,6 +172,72 @@ export const aethexUserService = { } as AethexUserProfile; }, + async getProfileById(userId: string): Promise { + if (!userId) return null; + if (!isSupabaseConfigured) { + const mock = await mockAuth.getUserProfile(userId as any); + return mock ? ({ ...(mock as any) } as AethexUserProfile) : null; + } + + const { data, error } = await supabase + .from("user_profiles") + .select("*") + .eq("id", userId) + .single(); + + if (error) { + if ((error as any)?.code === "PGRST116" || isTableMissing(error)) { + const fallback = await mockAuth.getUserProfile(userId as any); + return fallback ? ({ ...(fallback as any) } as AethexUserProfile) : null; + } + throw error; + } + + return data as AethexUserProfile; + }, + + async listProfiles(limit = 50): Promise { + if (!isSupabaseConfigured) { + return mockAuth.getAllProfiles().map( + (profile) => + ({ + ...(profile as any), + user_type: (profile as any).user_type || "community_member", + experience_level: + (profile as any).experience_level || "beginner", + }) as AethexUserProfile, + ); + } + + const { data, error } = await supabase + .from("user_profiles") + .select("*") + .order("updated_at", { ascending: false }) + .limit(limit); + + if (error) { + if (isTableMissing(error)) { + return mockAuth.getAllProfiles().map( + (profile) => + ({ + ...(profile as any), + user_type: (profile as any).user_type || "community_member", + experience_level: + (profile as any).experience_level || "beginner", + }) as AethexUserProfile, + ); + } + throw error; + } + + return (data as any[]).map( + (row) => + ({ + ...row, + }) as AethexUserProfile, + ); + }, + async updateProfile( userId: string, updates: Partial, @@ -475,7 +541,7 @@ export const aethexAchievementService = { id: "ach_level_master", name: "Level Master", description: "Reached level 5", - icon: "🏆", + icon: "��", xp_reward: 250, badge_color: "#f59e0b", created_at: new Date().toISOString(),