From 7f951526320d344206bfa3471147300a53fee95b Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 01:40:07 +0000 Subject: [PATCH] Prettier format pending files --- api/_supabase.ts | 3 +- api/achievements/award.ts | 25 +++++++++--- api/interests.ts | 20 ++++++--- api/profile/ensure.ts | 16 ++++++-- client/lib/aethex-database-adapter.ts | 59 ++++++++++++++++----------- client/pages/Onboarding.tsx | 7 +++- 6 files changed, 88 insertions(+), 42 deletions(-) diff --git a/api/_supabase.ts b/api/_supabase.ts index e8e7894f..2369d146 100644 --- a/api/_supabase.ts +++ b/api/_supabase.ts @@ -1,6 +1,7 @@ import { createClient } from "@supabase/supabase-js"; -const SUPABASE_URL = process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || ""; +const SUPABASE_URL = + process.env.SUPABASE_URL || process.env.VITE_SUPABASE_URL || ""; const SUPABASE_SERVICE_ROLE = process.env.SUPABASE_SERVICE_ROLE || ""; export function getAdminClient() { diff --git a/api/achievements/award.ts b/api/achievements/award.ts index 995fb2c3..c1d067a4 100644 --- a/api/achievements/award.ts +++ b/api/achievements/award.ts @@ -2,10 +2,17 @@ import type { VercelRequest, VercelResponse } from "@vercel/node"; import { getAdminClient } from "../../api/_supabase"; export default async function handler(req: VercelRequest, res: VercelResponse) { - if (req.method !== "POST") return res.status(405).json({ error: "Method not allowed" }); - const { user_id, achievement_names } = (req.body || {}) as { user_id?: string; achievement_names?: string[] }; + if (req.method !== "POST") + return res.status(405).json({ error: "Method not allowed" }); + const { user_id, achievement_names } = (req.body || {}) as { + user_id?: string; + achievement_names?: string[]; + }; if (!user_id) return res.status(400).json({ error: "user_id required" }); - const names = Array.isArray(achievement_names) && achievement_names.length ? achievement_names : ["Welcome to AeThex"]; + const names = + Array.isArray(achievement_names) && achievement_names.length + ? achievement_names + : ["Welcome to AeThex"]; try { const admin = getAdminClient(); @@ -15,18 +22,24 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { .in("name", names); if (aErr) return res.status(500).json({ error: aErr.message }); - const rows = (achievements || []).map((a: any) => ({ user_id, achievement_id: a.id })); + const rows = (achievements || []).map((a: any) => ({ + user_id, + achievement_id: a.id, + })); if (!rows.length) return res.json({ ok: true, awarded: [] }); const { error: iErr } = await admin .from("user_achievements") .upsert(rows as any, { onConflict: "user_id,achievement_id" as any }); - if (iErr && iErr.code !== "23505") return res.status(500).json({ error: iErr.message }); + if (iErr && iErr.code !== "23505") + return res.status(500).json({ error: iErr.message }); return res.json({ ok: true, awarded: rows.length }); } catch (e: any) { if (/SUPABASE_/.test(String(e?.message || ""))) { - return res.status(500).json({ error: `Server misconfigured: ${e.message}` }); + return res + .status(500) + .json({ error: `Server misconfigured: ${e.message}` }); } return res.status(500).json({ error: e?.message || String(e) }); } diff --git a/api/interests.ts b/api/interests.ts index 496ec498..582de45f 100644 --- a/api/interests.ts +++ b/api/interests.ts @@ -2,13 +2,21 @@ import type { VercelRequest, VercelResponse } from "@vercel/node"; import { getAdminClient } from "./_supabase"; export default async function handler(req: VercelRequest, res: VercelResponse) { - if (req.method !== "POST") return res.status(405).json({ error: "Method not allowed" }); - const { user_id, interests } = (req.body || {}) as { user_id?: string; interests?: string[] }; - if (!user_id || !Array.isArray(interests)) return res.status(400).json({ error: "invalid payload" }); + if (req.method !== "POST") + return res.status(405).json({ error: "Method not allowed" }); + const { user_id, interests } = (req.body || {}) as { + user_id?: string; + interests?: string[]; + }; + if (!user_id || !Array.isArray(interests)) + return res.status(400).json({ error: "invalid payload" }); try { const admin = getAdminClient(); - const { error: delErr } = await admin.from("user_interests").delete().eq("user_id", user_id); + const { error: delErr } = await admin + .from("user_interests") + .delete() + .eq("user_id", user_id); if (delErr) return res.status(500).json({ error: delErr.message }); if (interests.length) { @@ -20,7 +28,9 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { return res.json({ ok: true }); } catch (e: any) { if (/SUPABASE_/.test(String(e?.message || ""))) { - return res.status(500).json({ error: `Server misconfigured: ${e.message}` }); + return res + .status(500) + .json({ error: `Server misconfigured: ${e.message}` }); } return res.status(500).json({ error: e?.message || String(e) }); } diff --git a/api/profile/ensure.ts b/api/profile/ensure.ts index 160ff877..a66158be 100644 --- a/api/profile/ensure.ts +++ b/api/profile/ensure.ts @@ -2,7 +2,8 @@ import type { VercelRequest, VercelResponse } from "@vercel/node"; import { getAdminClient } from "../_supabase"; export default async function handler(req: VercelRequest, res: VercelResponse) { - if (req.method !== "POST") return res.status(405).json({ error: "Method not allowed" }); + if (req.method !== "POST") + return res.status(405).json({ error: "Method not allowed" }); const { id, profile } = (req.body || {}) as { id?: string; profile?: any }; if (!id) return res.status(400).json({ error: "missing id" }); @@ -47,19 +48,26 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { } if (error) { - if ((error as any).code === "23503" || (error as any).message?.includes("foreign key")) { + if ( + (error as any).code === "23503" || + (error as any).message?.includes("foreign key") + ) { return res.status(400).json({ error: "User does not exist in authentication system. Please sign out and sign back in, then retry onboarding.", }); } - return res.status(500).json({ error: (error as any).message || "Unknown error" }); + return res + .status(500) + .json({ error: (error as any).message || "Unknown error" }); } return res.json(attempt.data || {}); } catch (e: any) { if (/SUPABASE_/.test(String(e?.message || ""))) { - return res.status(500).json({ error: `Server misconfigured: ${e.message}` }); + return res + .status(500) + .json({ error: `Server misconfigured: ${e.message}` }); } return res.status(500).json({ error: e?.message || String(e) }); } diff --git a/client/lib/aethex-database-adapter.ts b/client/lib/aethex-database-adapter.ts index 20a13f0b..a50d2211 100644 --- a/client/lib/aethex-database-adapter.ts +++ b/client/lib/aethex-database-adapter.ts @@ -87,12 +87,15 @@ export const aethexUserService = { if (!isSupabaseConfigured) { const mock = (await mockAuth.getUserProfile(user.id as any)) || - (await mockAuth.updateProfile(user.id as any, { - username: user.email?.split("@")[0] || "user", - email: user.email || "", - role: "member", - onboarded: true, - } as any)); + (await mockAuth.updateProfile( + user.id as any, + { + username: user.email?.split("@")[0] || "user", + email: user.email || "", + role: "member", + onboarded: true, + } as any, + )); return { ...(mock as any), email: user.email } as AethexUserProfile; } @@ -194,17 +197,20 @@ export const aethexUserService = { profileData: Partial, ): Promise { if (!isSupabaseConfigured) { - const mock = await mockAuth.updateProfile(userId as any, { - username: profileData.username || `user_${Date.now()}`, - full_name: profileData.full_name, - bio: profileData.bio, - location: profileData.location, - linkedin_url: profileData.linkedin_url as any, - github_url: profileData.github_url as any, - twitter_url: profileData.twitter_url as any, - level: 1, - total_xp: 0, - } as any); + const mock = await mockAuth.updateProfile( + userId as any, + { + username: profileData.username || `user_${Date.now()}`, + full_name: profileData.full_name, + bio: profileData.bio, + location: profileData.location, + linkedin_url: profileData.linkedin_url as any, + github_url: profileData.github_url as any, + twitter_url: profileData.twitter_url as any, + level: 1, + total_xp: 0, + } as any, + ); return { ...(mock as any), onboarded: true, @@ -593,12 +599,14 @@ export const aethexAchievementService = { if (!error && profile) { const newTotalXP = ((profile as any).total_xp || 0) + xpGained; const newLevel = Math.floor(newTotalXP / 1000) + 1; - const newLoyaltyPoints = ((profile as any).loyalty_points || 0) + xpGained; + const newLoyaltyPoints = + ((profile as any).loyalty_points || 0) + xpGained; const updates: any = {}; if ("total_xp" in (profile as any)) updates.total_xp = newTotalXP; if ("level" in (profile as any)) updates.level = newLevel; - if ("loyalty_points" in (profile as any)) updates.loyalty_points = newLoyaltyPoints; + if ("loyalty_points" in (profile as any)) + updates.loyalty_points = newLoyaltyPoints; if (Object.keys(updates).length > 0) { await supabase.from("user_profiles").update(updates).eq("id", userId); @@ -628,11 +636,14 @@ export const aethexAchievementService = { const total_xp = ((current as any)?.total_xp || 0) + xpGained; const level = Math.floor(total_xp / 1000) + 1; const loyalty_points = ((current as any)?.loyalty_points || 0) + xpGained; - await mockAuth.updateProfile(userId as any, { - total_xp, - level, - loyalty_points, - } as any); + await mockAuth.updateProfile( + userId as any, + { + total_xp, + level, + loyalty_points, + } as any, + ); if (level > ((current as any)?.level || 1) && level >= 5) { await this.awardAchievement(userId, "ach_level_master"); } diff --git a/client/pages/Onboarding.tsx b/client/pages/Onboarding.tsx index 8748c576..831edf9f 100644 --- a/client/pages/Onboarding.tsx +++ b/client/pages/Onboarding.tsx @@ -161,8 +161,11 @@ export default function Onboarding() { try { parsedError = JSON.parse(text); } catch {} - const message = parsedError?.error || text || `HTTP ${ensureResp.status}`; - throw new Error(`Server endpoint missing and client fallback failed: ${message}`); + const message = + parsedError?.error || text || `HTTP ${ensureResp.status}`; + throw new Error( + `Server endpoint missing and client fallback failed: ${message}`, + ); } } else { const text = await ensureResp.text().catch(() => "");