Prettier format pending files

This commit is contained in:
Builder.io 2025-09-30 01:40:07 +00:00
parent c104e87475
commit 7f95152632
6 changed files with 88 additions and 42 deletions

View file

@ -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() {

View file

@ -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) });
}

View file

@ -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) });
}

View file

@ -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) });
}

View file

@ -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<AethexUserProfile>,
): Promise<AethexUserProfile | null> {
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");
}

View file

@ -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(() => "");