From 8bb2b77bc59b0353c91f756929061137367bbbb1 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 29 Sep 2025 00:15:54 +0000 Subject: [PATCH] Add server API for featured studios and wire client to Supabase-backed endpoints cgen-6596e078273547e8932d84a17deb7656 --- server/index.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/index.ts b/server/index.ts index e4cbb85c..7b0ef38e 100644 --- a/server/index.ts +++ b/server/index.ts @@ -194,6 +194,43 @@ export function createServer() { } }); + app.get("/api/featured-studios", async (_req, res) => { + try { + const { data, error } = await adminSupabase + .from("featured_studios") + .select("*") + .order("rank", { ascending: true, nullsFirst: true } as any) + .order("name", { ascending: true }); + if (error) return res.status(500).json({ error: error.message }); + res.json(data || []); + } catch (e: any) { + res.status(500).json({ error: e?.message || String(e) }); + } + }); + + app.post("/api/featured-studios", async (req, res) => { + const studios = (req.body?.studios || []) as any[]; + if (!Array.isArray(studios)) + return res.status(400).json({ error: "studios must be an array" }); + try { + const rows = studios.map((s: any, idx: number) => ({ + id: s.id, + name: String(s.name || "").trim(), + tagline: s.tagline || null, + metrics: s.metrics || null, + specialties: Array.isArray(s.specialties) ? s.specialties : null, + rank: Number.isFinite(s.rank) ? s.rank : idx, + })); + const { error } = await adminSupabase + .from("featured_studios") + .upsert(rows as any, { onConflict: "name" as any }); + if (error) return res.status(500).json({ error: error.message }); + res.json({ ok: true, count: rows.length }); + } catch (e: any) { + res.status(500).json({ error: e?.message || String(e) }); + } + }); + app.post("/api/achievements/award", async (req, res) => { const { user_id, achievement_names } = req.body || {}; if (!user_id) return res.status(400).json({ error: "user_id required" });